Skip to content

Commit

Permalink
Add new CosmosDBSQLDatabase CRD (#1549)
Browse files Browse the repository at this point in the history
* Update CosmosDB SDK version
* Refactor CosmosDB folder structure
  - This is in preparation for adding new CosmosDB resources.
* Rename HandleEnsureError with a clearer name
  - Also add documentation.
* Add new CosmosDBSQLDatabase resource
* Add PollURLKind to status
  - Use it to differentiate between Create/Delete polling.
  • Loading branch information
matthchr authored Jun 8, 2021
1 parent 37c7965 commit 2f6cc6f
Show file tree
Hide file tree
Showing 32 changed files with 1,491 additions and 110 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ test-unit: generate fmt vet manifests
TEST_USE_EXISTING_CLUSTER=false REQUEUE_AFTER=20 \
go test -v -tags "$(BUILD_TAGS)" -coverprofile=reports/unittest-coverage-ouput.txt -covermode count -parallel 4 -timeout 10m \
./pkg/resourcemanager/keyvaults/unittest/ \
./pkg/resourcemanager/azuresql/azuresqlfailovergroup
./pkg/resourcemanager/azuresql/azuresqlfailovergroup \
./pkg/resourcemanager/cosmosdb/sqldatabase
# The below folders are commented out because the tests in them fail...
# ./api/... \

Expand Down
12 changes: 12 additions & 0 deletions api/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package api

// +kubebuilder:validation:Enum={"CreateOrUpdate","Delete"}
type PollingURLKind string

const (
PollingURLKindCreateOrUpdate = PollingURLKind("CreateOrUpdate")
PollingURLKindDelete = PollingURLKind("Delete")
)
42 changes: 28 additions & 14 deletions api/v1alpha1/aso_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,40 @@

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
"github.com/Azure/azure-service-operator/api"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ASOStatus (AzureServiceOperatorsStatus) defines the observed state of resource actions
type ASOStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
State string `json:"state,omitempty"`
Message string `json:"message,omitempty"`
ResourceId string `json:"resourceId,omitempty"`
PollingURL string `json:"pollingUrl,omitempty"`
SpecHash string `json:"specHash,omitempty"`
ContainsUpdate bool `json:"containsUpdate,omitempty"` // TODO: Unused, remove in future version
RequestedAt *metav1.Time `json:"requested,omitempty"`
CompletedAt *metav1.Time `json:"completed,omitempty"`
FailedProvisioning bool `json:"failedProvisioning,omitempty"`
FlattenedSecrets bool `json:"flattenedSecrets,omitempty"`
Output string `json:"output,omitempty"`
Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
State string `json:"state,omitempty"`
Message string `json:"message,omitempty"`
ResourceId string `json:"resourceId,omitempty"`
PollingURL string `json:"pollingUrl,omitempty"`
PollingURLKind *api.PollingURLKind `json:"pollingUrlKind,omitempty"`
SpecHash string `json:"specHash,omitempty"`
ContainsUpdate bool `json:"containsUpdate,omitempty"` // TODO: Unused, remove in future version
RequestedAt *metav1.Time `json:"requested,omitempty"`
CompletedAt *metav1.Time `json:"completed,omitempty"`
FailedProvisioning bool `json:"failedProvisioning,omitempty"`
FlattenedSecrets bool `json:"flattenedSecrets,omitempty"`
Output string `json:"output,omitempty"`
}

func (s *ASOStatus) SetPollingURL(url string, kind api.PollingURLKind) {
s.PollingURL = url
s.PollingURLKind = &kind
}

func (s *ASOStatus) ClearPollingURL() {
s.PollingURL = ""
s.PollingURLKind = nil
}

func (s *ASOStatus) SetProvisioned(msg string) {
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/cosmosdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ type CosmosDBSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:MinLength=0

// +kubebuilder:validation:Required
// Location is the Azure location where the CosmosDB exists
Location string `json:"location,omitempty"`

// +kubebuilder:validation:Pattern=^[-\w\._\(\)]+$
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:Required
Expand Down
78 changes: 78 additions & 0 deletions api/v1alpha1/cosmosdbsqldatabase_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// CosmosDBSQLDatabaseSpec defines the desired state of the CosmosDBSQLDatabase
type CosmosDBSQLDatabaseSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:Pattern=^[-\w\._\(\)]+$
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:Required
// ResourceGroup is the resource group the CosmosDBSQLDatabase will be created in.
ResourceGroup string `json:"resourceGroup"`

// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:Required
// Account is the account that the SQL database will be created in.
Account string `json:"cosmosDBAccount"`

// +kubebuilder:validation:Min=400
// Throughput is the user specified manual throughput (RU/s) for the database expressed in units of 100 request
// units per second. The minimum is 400 up to 1,000,000 (or higher by requesting a limit increase).
// This must not be specified if autoscale is specified. This cannot be changed after creation if it
// (or autoscaleSettings) was not set to something initially.
Throughput *int32 `json:"throughput,omitempty"`

// AutoscaleSettings contains the user specified autoscale configuration.
// This must not be specified if Throughput is specified. This cannot be changed after creation if it
// (or throughput) was not set to something initially.
AutoscaleSettings *AutoscaleSettings `json:"autoscaleSettings,omitempty"`

// Tags are key-value pairs associated with the resource.
Tags map[string]string `json:"tags,omitempty"`
}

type AutoscaleSettings struct {
// +kubebuilder:validation:Min=0
// MaxThroughput is the autoscale max RU/s of the database.
MaxThroughput *int32 `json:"maxThroughput,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// CosmosDBSQLDatabase is the Schema for the cosmosdbsql API
// +kubebuilder:resource:shortName=cdbsql
// +kubebuilder:printcolumn:name="Provisioned",type="string",JSONPath=".status.provisioned"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message"
type CosmosDBSQLDatabase struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CosmosDBSQLDatabaseSpec `json:"spec,omitempty"`
Status ASOStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// CosmosDBSQLDatabaseList contains a list of CosmosDBSQLDatabase
type CosmosDBSQLDatabaseList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CosmosDBSQLDatabase `json:"items"`
}

func init() {
SchemeBuilder.Register(&CosmosDBSQLDatabase{}, &CosmosDBSQLDatabaseList{})
}
117 changes: 117 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 28 additions & 14 deletions api/v1alpha2/aso_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,40 @@

package v1alpha2

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
"github.com/Azure/azure-service-operator/api"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ASOStatus (AzureServiceOperatorsStatus) defines the observed state of resource actions
type ASOStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
State string `json:"state,omitempty"`
Message string `json:"message,omitempty"`
ResourceId string `json:"resourceId,omitempty"`
PollingURL string `json:"pollingUrl,omitempty"`
SpecHash string `json:"specHash,omitempty"`
ContainsUpdate bool `json:"containsUpdate,omitempty"` // TODO: Unused, remove in future version
RequestedAt *metav1.Time `json:"requested,omitempty"`
CompletedAt *metav1.Time `json:"completed,omitempty"`
FailedProvisioning bool `json:"failedProvisioning,omitempty"`
FlattenedSecrets bool `json:"flattenedSecrets,omitempty"`
Output string `json:"output,omitempty"`
Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
State string `json:"state,omitempty"`
Message string `json:"message,omitempty"`
ResourceId string `json:"resourceId,omitempty"`
PollingURL string `json:"pollingUrl,omitempty"`
PollingURLKind *api.PollingURLKind `json:"pollingUrlKind,omitempty"`
SpecHash string `json:"specHash,omitempty"`
ContainsUpdate bool `json:"containsUpdate,omitempty"` // TODO: Unused, remove in future version
RequestedAt *metav1.Time `json:"requested,omitempty"`
CompletedAt *metav1.Time `json:"completed,omitempty"`
FailedProvisioning bool `json:"failedProvisioning,omitempty"`
FlattenedSecrets bool `json:"flattenedSecrets,omitempty"`
Output string `json:"output,omitempty"`
}

func (s *ASOStatus) SetPollingURL(url string, kind api.PollingURLKind) {
s.PollingURL = url
s.PollingURLKind = &kind
}

func (s *ASOStatus) ClearPollingURL() {
s.PollingURL = ""
s.PollingURLKind = nil
}

func (s *ASOStatus) SetProvisioned(msg string) {
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2f6cc6f

Please sign in to comment.