diff --git a/PROJECT b/PROJECT index b9d401f9b11..41ea677330d 100644 --- a/PROJECT +++ b/PROJECT @@ -22,13 +22,13 @@ resources: kind: EventhubNamespace - group: azure version: v1alpha1 - kind: SqlServer + kind: AzureSqlServer - group: azure version: v1alpha1 - kind: SqlDatabase + kind: AzureSqlDatabase - group: azure version: v1alpha1 - kind: SqlFirewallRule + kind: AzureSqlFirewallRule - group: azure version: v1alpha1 kind: KeyVault @@ -37,4 +37,4 @@ resources: kind: ConsumerGroup - group: azure version: v1alpha1 - kind: SqlAction + kind: AzureSqlAction diff --git a/api/v1alpha1/sqlaction_types.go b/api/v1alpha1/azuresqlaction_types.go similarity index 72% rename from api/v1alpha1/sqlaction_types.go rename to api/v1alpha1/azuresqlaction_types.go index 61d098be467..91b4863c7d9 100644 --- a/api/v1alpha1/sqlaction_types.go +++ b/api/v1alpha1/azuresqlaction_types.go @@ -22,8 +22,8 @@ import ( // 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. -// SqlActionSpec defines the desired state of SqlAction -type SqlActionSpec struct { +// AzureSqlActionSpec defines the desired state of AzureSqlAction +type AzureSqlActionSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file ResourceGroup string `json:"resourcegroup"` @@ -31,8 +31,8 @@ type SqlActionSpec struct { ServerName string `json:"servername"` } -// SqlActionStatus defines the observed state of SqlAction -type SqlActionStatus struct { +// AzureSqlActionStatus defines the observed state of AzureSqlAction +type AzureSqlActionStatus 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"` @@ -43,28 +43,28 @@ type SqlActionStatus struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status -// SqlAction is the Schema for the sqlactions API -type SqlAction struct { +// AzureSqlAction is the Schema for the azuresqlactions API +type AzureSqlAction struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SqlActionSpec `json:"spec,omitempty"` - Status SqlActionStatus `json:"status,omitempty"` + Spec AzureSqlActionSpec `json:"spec,omitempty"` + Status AzureSqlActionStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true -// SqlActionList contains a list of SqlAction -type SqlActionList struct { +// AzureSqlActionList contains a list of AzureSqlAction +type AzureSqlActionList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []SqlAction `json:"items"` + Items []AzureSqlAction `json:"items"` } func init() { - SchemeBuilder.Register(&SqlAction{}, &SqlActionList{}) + SchemeBuilder.Register(&AzureSqlAction{}, &AzureSqlActionList{}) } -func (s *SqlAction) IsSubmitted() bool { +func (s *AzureSqlAction) IsSubmitted() bool { return s.Status.Provisioned || s.Status.Provisioning } diff --git a/api/v1alpha1/sqldatabase_types.go b/api/v1alpha1/azuresqldatabase_types.go similarity index 71% rename from api/v1alpha1/sqldatabase_types.go rename to api/v1alpha1/azuresqldatabase_types.go index d890a8b1f4a..52d2cecd358 100644 --- a/api/v1alpha1/sqldatabase_types.go +++ b/api/v1alpha1/azuresqldatabase_types.go @@ -22,8 +22,8 @@ import ( // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. -// SqlDatabaseSpec defines the desired state of SqlDatabase -type SqlDatabaseSpec struct { +// AzureSqlDatabaseSpec defines the desired state of AzureSqlDatabase +type AzureSqlDatabaseSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file Location string `json:"location"` @@ -32,8 +32,8 @@ type SqlDatabaseSpec struct { Edition sql.DBEdition `json:"edition"` } -// SqlDatabaseStatus defines the observed state of SqlDatabase -type SqlDatabaseStatus struct { +// AzureSqlDatabaseStatus defines the observed state of AzureSqlDatabase +type AzureSqlDatabaseStatus 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"` @@ -42,28 +42,28 @@ type SqlDatabaseStatus struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status -// SqlDatabase is the Schema for the sqldatabases API -type SqlDatabase struct { +// AzureSqlDatabase is the Schema for the azuresqldatabases API +type AzureSqlDatabase struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SqlDatabaseSpec `json:"spec,omitempty"` - Status SqlDatabaseStatus `json:"status,omitempty"` + Spec AzureSqlDatabaseSpec `json:"spec,omitempty"` + Status AzureSqlDatabaseStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true -// SqlDatabaseList contains a list of SqlDatabase -type SqlDatabaseList struct { +// AzureSqlDatabaseList contains a list of AzureSqlDatabase +type AzureSqlDatabaseList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []SqlDatabase `json:"items"` + Items []AzureSqlDatabase `json:"items"` } func init() { - SchemeBuilder.Register(&SqlDatabase{}, &SqlDatabaseList{}) + SchemeBuilder.Register(&AzureSqlDatabase{}, &AzureSqlDatabaseList{}) } -func (s *SqlDatabase) IsSubmitted() bool { +func (s *AzureSqlDatabase) IsSubmitted() bool { return s.Status.Provisioned } diff --git a/api/v1alpha1/sqldatabase_types_test.go b/api/v1alpha1/azuresqldatabase_types_test.go similarity index 92% rename from api/v1alpha1/sqldatabase_types_test.go rename to api/v1alpha1/azuresqldatabase_types_test.go index bb6fa20690c..85d3b823552 100644 --- a/api/v1alpha1/sqldatabase_types_test.go +++ b/api/v1alpha1/azuresqldatabase_types_test.go @@ -27,10 +27,10 @@ import ( // These tests are written in BDD-style using Ginkgo framework. Refer to // http://onsi.github.io/ginkgo to learn more. -var _ = Describe("SqlDatabase", func() { +var _ = Describe("AzureSqlDatabase", func() { var ( key types.NamespacedName - created, fetched *SqlDatabase + created, fetched *AzureSqlDatabase ) BeforeEach(func() { @@ -53,12 +53,12 @@ var _ = Describe("SqlDatabase", func() { Name: "foo", Namespace: "default", } - created = &SqlDatabase{ + created = &AzureSqlDatabase{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "default", }, - Spec: SqlDatabaseSpec{ + Spec: AzureSqlDatabaseSpec{ Location: "westus", ResourceGroup: "foo-resourcegroup", Server: "sqlsrvsample", @@ -68,7 +68,7 @@ var _ = Describe("SqlDatabase", func() { By("creating an API obj") Expect(k8sClient.Create(context.TODO(), created)).To(Succeed()) - fetched = &SqlDatabase{} + fetched = &AzureSqlDatabase{} Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed()) Expect(fetched).To(Equal(created)) diff --git a/api/v1alpha1/sqlfirewallrule_types.go b/api/v1alpha1/azuresqlfirewallrule_types.go similarity index 69% rename from api/v1alpha1/sqlfirewallrule_types.go rename to api/v1alpha1/azuresqlfirewallrule_types.go index 76e02dcab3d..0d839aac97a 100644 --- a/api/v1alpha1/sqlfirewallrule_types.go +++ b/api/v1alpha1/azuresqlfirewallrule_types.go @@ -22,8 +22,8 @@ import ( // 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. -// SqlFirewallRuleSpec defines the desired state of SqlFirewallRule -type SqlFirewallRuleSpec struct { +// AzureSqlFirewallRuleSpec defines the desired state of AzureSqlFirewallRule +type AzureSqlFirewallRuleSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file ResourceGroup string `json:"resourcegroup,omitempty"` @@ -32,8 +32,8 @@ type SqlFirewallRuleSpec struct { EndIPAddress string `json:"endipaddress,omitempty"` } -// SqlFirewallRuleStatus defines the observed state of SqlFirewallRule -type SqlFirewallRuleStatus struct { +// AzureSqlFirewallRuleStatus defines the observed state of AzureSqlFirewallRule +type AzureSqlFirewallRuleStatus 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"` @@ -42,28 +42,28 @@ type SqlFirewallRuleStatus struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status -// SqlFirewallRule is the Schema for the sqlfirewallrules API -type SqlFirewallRule struct { +// AzureSqlFirewallRule is the Schema for the azuresqlfirewallrules API +type AzureSqlFirewallRule struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SqlFirewallRuleSpec `json:"spec,omitempty"` - Status SqlFirewallRuleStatus `json:"status,omitempty"` + Spec AzureSqlFirewallRuleSpec `json:"spec,omitempty"` + Status AzureSqlFirewallRuleStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true -// SqlFirewallRuleList contains a list of SqlFirewallRule -type SqlFirewallRuleList struct { +// AzureSqlFirewallRuleList contains a list of AzureSqlFirewallRule +type AzureSqlFirewallRuleList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []SqlFirewallRule `json:"items"` + Items []AzureSqlFirewallRule `json:"items"` } func init() { - SchemeBuilder.Register(&SqlFirewallRule{}, &SqlFirewallRuleList{}) + SchemeBuilder.Register(&AzureSqlFirewallRule{}, &AzureSqlFirewallRuleList{}) } -func (s *SqlFirewallRule) IsSubmitted() bool { +func (s *AzureSqlFirewallRule) IsSubmitted() bool { return s.Status.Provisioning || s.Status.Provisioned } diff --git a/api/v1alpha1/sqlserver_types.go b/api/v1alpha1/azuresqlserver_types.go similarity index 71% rename from api/v1alpha1/sqlserver_types.go rename to api/v1alpha1/azuresqlserver_types.go index 4ec71a9a459..aa8cae11e4b 100644 --- a/api/v1alpha1/sqlserver_types.go +++ b/api/v1alpha1/azuresqlserver_types.go @@ -22,16 +22,16 @@ import ( // 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. -// SqlServerSpec defines the desired state of SqlServer -type SqlServerSpec struct { +// AzureSqlServerSpec defines the desired state of AzureSqlServer +type AzureSqlServerSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file Location string `json:"location"` ResourceGroup string `json:"resourcegroup,omitempty"` } -// SqlServerStatus defines the observed state of SqlServer -type SqlServerStatus struct { +// AzureSqlServerStatus defines the observed state of AzureSqlServer +type AzureSqlServerStatus 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"` @@ -42,32 +42,32 @@ type SqlServerStatus struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status -// SqlServer is the Schema for the sqlservers API -type SqlServer struct { +// AzureSqlServer is the Schema for the azuresqlservers API +type AzureSqlServer struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SqlServerSpec `json:"spec,omitempty"` - Status SqlServerStatus `json:"status,omitempty"` + Spec AzureSqlServerSpec `json:"spec,omitempty"` + Status AzureSqlServerStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true -// SqlServerList contains a list of SqlServer -type SqlServerList struct { +// AzureSqlServerList contains a list of AzureSqlServer +type AzureSqlServerList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []SqlServer `json:"items"` + Items []AzureSqlServer `json:"items"` } func init() { - SchemeBuilder.Register(&SqlServer{}, &SqlServerList{}) + SchemeBuilder.Register(&AzureSqlServer{}, &AzureSqlServerList{}) } -func (s *SqlServer) IsSubmitted() bool { +func (s *AzureSqlServer) IsSubmitted() bool { return s.Status.Provisioned || s.Status.Provisioning } -func (s *SqlServer) IsProvisioned() bool { +func (s *AzureSqlServer) IsProvisioned() bool { return s.Status.Provisioned } diff --git a/api/v1alpha1/sqlserver_types_test.go b/api/v1alpha1/azuresqlserver_types_test.go similarity index 92% rename from api/v1alpha1/sqlserver_types_test.go rename to api/v1alpha1/azuresqlserver_types_test.go index e6dfcbcda7d..09e5d413bae 100644 --- a/api/v1alpha1/sqlserver_types_test.go +++ b/api/v1alpha1/azuresqlserver_types_test.go @@ -27,10 +27,10 @@ import ( // These tests are written in BDD-style using Ginkgo framework. Refer to // http://onsi.github.io/ginkgo to learn more. -var _ = Describe("SqlServer", func() { +var _ = Describe("AzureSqlServer", func() { var ( key types.NamespacedName - created, fetched *SqlServer + created, fetched *AzureSqlServer ) BeforeEach(func() { @@ -53,12 +53,12 @@ var _ = Describe("SqlServer", func() { Name: "foo", Namespace: "default", } - created = &SqlServer{ + created = &AzureSqlServer{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "default", }, - Spec: SqlServerSpec{ + Spec: AzureSqlServerSpec{ Location: "westus", ResourceGroup: "foo-resourcegroup", }} @@ -66,7 +66,7 @@ var _ = Describe("SqlServer", func() { By("creating an API obj") Expect(k8sClient.Create(context.TODO(), created)).To(Succeed()) - fetched = &SqlServer{} + fetched = &AzureSqlServer{} Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed()) Expect(fetched).To(Equal(created)) diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index fe3ac10d11a..1c79bbfda43 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -10,10 +10,10 @@ resources: - bases/azure.microsoft.com_eventhubnamespaces.yaml - bases/azure.microsoft.com_consumergroups.yaml - bases/azure.microsoft.com_keyvaults.yaml -- bases/azure.microsoft.com_sqlservers.yaml -- bases/azure.microsoft.com_sqldatabases.yaml -- bases/azure.microsoft.com_sqlfirewallrules.yaml -- bases/azure.microsoft.com_sqlactions.yaml +- bases/azure.microsoft.com_azuresqlservers.yaml +- bases/azure.microsoft.com_azuresqldatabases.yaml +- bases/azure.microsoft.com_azuresqlfirewallrules.yaml +- bases/azure.microsoft.com_azuresqlactions.yaml # +kubebuilder:scaffold:crdkustomizeresource patches: @@ -23,10 +23,10 @@ patches: #- patches/webhook_in_eventhubnamespaces.yaml #- patches/webhook_in_consumergroups.yaml #- patches/webhook_in_keyvaults.yaml -#- patches/webhook_in_sqlservers.yaml -#- patches/webhook_in_sqldatabases.yaml -#- patches/webhook_in_sqlfirewallrules.yaml -#- patches/webhook_in_sqlactions.yaml +#- patches/webhook_in_azuresqlservers.yaml +#- patches/webhook_in_azuresqldatabases.yaml +#- patches/webhook_in_azuresqlfirewallrules.yaml +#- patches/webhook_in_azuresqlactions.yaml # +kubebuilder:scaffold:crdkustomizewebhookpatch # [CAINJECTION] patches here are for enabling the CA injection for each CRD @@ -35,10 +35,10 @@ patches: #- patches/cainjection_in_eventhubnamespaces.yaml #- patches/cainjection_in_consumergroups.yaml #- patches/cainjection_in_keyvaults.yaml -#- patches/cainjection_in_sqlservers.yaml -#- patches/cainjection_in_sqldatabases.yaml -#- patches/cainjection_in_sqlfirewallrules.yaml -#- patches/cainjection_in_sqlactions.yaml +#- patches/cainjection_in_azuresqlservers.yaml +#- patches/cainjection_in_azuresqldatabases.yaml +#- patches/cainjection_in_azuresqlfirewallrules.yaml +#- patches/cainjection_in_azuresqlactions.yaml # +kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/crd/patches/cainjection_in_sqlactions.yaml b/config/crd/patches/cainjection_in_azuresqlactions.yaml similarity index 87% rename from config/crd/patches/cainjection_in_sqlactions.yaml rename to config/crd/patches/cainjection_in_azuresqlactions.yaml index 2e02acdc74c..b86e1c21328 100644 --- a/config/crd/patches/cainjection_in_sqlactions.yaml +++ b/config/crd/patches/cainjection_in_azuresqlactions.yaml @@ -5,4 +5,4 @@ kind: CustomResourceDefinition metadata: annotations: certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: sqlactions.azure.microsoft.com + name: azuresqlactions.azure.microsoft.com diff --git a/config/crd/patches/cainjection_in_sqlfirewallrules.yaml b/config/crd/patches/cainjection_in_azuresqldatabases.yaml similarity index 86% rename from config/crd/patches/cainjection_in_sqlfirewallrules.yaml rename to config/crd/patches/cainjection_in_azuresqldatabases.yaml index 6d06e8d4927..1fd8a6c8670 100644 --- a/config/crd/patches/cainjection_in_sqlfirewallrules.yaml +++ b/config/crd/patches/cainjection_in_azuresqldatabases.yaml @@ -5,4 +5,4 @@ kind: CustomResourceDefinition metadata: annotations: certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: sqlfirewallrules.azure.microsoft.com + name: azuresqldatabases.azure.microsoft.com diff --git a/config/crd/patches/cainjection_in_sqlservers.yaml b/config/crd/patches/cainjection_in_azuresqlfirewallrules.yaml similarity index 85% rename from config/crd/patches/cainjection_in_sqlservers.yaml rename to config/crd/patches/cainjection_in_azuresqlfirewallrules.yaml index 21f5baa3375..2963dcb6bf4 100644 --- a/config/crd/patches/cainjection_in_sqlservers.yaml +++ b/config/crd/patches/cainjection_in_azuresqlfirewallrules.yaml @@ -5,4 +5,4 @@ kind: CustomResourceDefinition metadata: annotations: certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: sqlservers.azure.microsoft.com + name: azuresqlfirewallrules.azure.microsoft.com diff --git a/config/crd/patches/cainjection_in_sqldatabases.yaml b/config/crd/patches/cainjection_in_azuresqlservers.yaml similarity index 87% rename from config/crd/patches/cainjection_in_sqldatabases.yaml rename to config/crd/patches/cainjection_in_azuresqlservers.yaml index 7aecaee74eb..b69ce6092ea 100644 --- a/config/crd/patches/cainjection_in_sqldatabases.yaml +++ b/config/crd/patches/cainjection_in_azuresqlservers.yaml @@ -5,4 +5,4 @@ kind: CustomResourceDefinition metadata: annotations: certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: sqldatabases.azure.microsoft.com + name: azuresqlservers.azure.microsoft.com diff --git a/config/crd/patches/webhook_in_sqlactions.yaml b/config/crd/patches/webhook_in_azuresqlactions.yaml similarity index 93% rename from config/crd/patches/webhook_in_sqlactions.yaml rename to config/crd/patches/webhook_in_azuresqlactions.yaml index 406f6ad3d10..94408f80adb 100644 --- a/config/crd/patches/webhook_in_sqlactions.yaml +++ b/config/crd/patches/webhook_in_azuresqlactions.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: sqlactions.azure.microsoft.com + name: azuresqlactions.azure.microsoft.com spec: conversion: strategy: Webhook diff --git a/config/crd/patches/webhook_in_sqlfirewallrules.yaml b/config/crd/patches/webhook_in_azuresqldatabases.yaml similarity index 92% rename from config/crd/patches/webhook_in_sqlfirewallrules.yaml rename to config/crd/patches/webhook_in_azuresqldatabases.yaml index c3f8f8e5d18..e12309d45df 100644 --- a/config/crd/patches/webhook_in_sqlfirewallrules.yaml +++ b/config/crd/patches/webhook_in_azuresqldatabases.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: sqlfirewallrules.azure.microsoft.com + name: azuresqldatabases.azure.microsoft.com spec: conversion: strategy: Webhook diff --git a/config/crd/patches/webhook_in_sqlservers.yaml b/config/crd/patches/webhook_in_azuresqlfirewallrules.yaml similarity index 92% rename from config/crd/patches/webhook_in_sqlservers.yaml rename to config/crd/patches/webhook_in_azuresqlfirewallrules.yaml index c87ac0e15ce..12c3929d394 100644 --- a/config/crd/patches/webhook_in_sqlservers.yaml +++ b/config/crd/patches/webhook_in_azuresqlfirewallrules.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: sqlservers.azure.microsoft.com + name: azuresqlfirewallrules.azure.microsoft.com spec: conversion: strategy: Webhook diff --git a/config/crd/patches/webhook_in_sqldatabases.yaml b/config/crd/patches/webhook_in_azuresqlservers.yaml similarity index 93% rename from config/crd/patches/webhook_in_sqldatabases.yaml rename to config/crd/patches/webhook_in_azuresqlservers.yaml index c78a062d413..4f1b8b07f8a 100644 --- a/config/crd/patches/webhook_in_sqldatabases.yaml +++ b/config/crd/patches/webhook_in_azuresqlservers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: sqldatabases.azure.microsoft.com + name: azuresqlservers.azure.microsoft.com spec: conversion: strategy: Webhook diff --git a/config/samples/azure_v1alpha1_azuresqlaction.yaml b/config/samples/azure_v1alpha1_azuresqlaction.yaml new file mode 100644 index 00000000000..92c5fb9b5a4 --- /dev/null +++ b/config/samples/azure_v1alpha1_azuresqlaction.yaml @@ -0,0 +1,8 @@ +apiVersion: azure.microsoft.com/v1alpha1 +kind: AzureSqlAction +metadata: + name: azuresqlaction-sample +spec: + resourcegroup: resourcegroup-azure-operators + actionname: rollcreds + servername: sqlserver-sample-777 diff --git a/config/samples/azure_v1alpha1_sqldatabase.yaml b/config/samples/azure_v1alpha1_azuresqldatabase.yaml similarity index 75% rename from config/samples/azure_v1alpha1_sqldatabase.yaml rename to config/samples/azure_v1alpha1_azuresqldatabase.yaml index 70aeaa4549c..7f9601ce2f2 100644 --- a/config/samples/azure_v1alpha1_sqldatabase.yaml +++ b/config/samples/azure_v1alpha1_azuresqldatabase.yaml @@ -1,7 +1,7 @@ apiVersion: azure.microsoft.com/v1alpha1 -kind: SqlDatabase +kind: AzureSqlDatabase metadata: - name: sqldatabase-sample + name: azuresqldatabase-sample spec: location: westus resourcegroup: resourcegroup-azure-operators diff --git a/config/samples/azure_v1alpha1_sqlfirewallrule.yaml b/config/samples/azure_v1alpha1_azuresqlfirewallrule.yaml similarity index 90% rename from config/samples/azure_v1alpha1_sqlfirewallrule.yaml rename to config/samples/azure_v1alpha1_azuresqlfirewallrule.yaml index c218326e465..41f55fb62bc 100644 --- a/config/samples/azure_v1alpha1_sqlfirewallrule.yaml +++ b/config/samples/azure_v1alpha1_azuresqlfirewallrule.yaml @@ -1,5 +1,5 @@ apiVersion: azure.microsoft.com/v1alpha1 -kind: SqlFirewallRule +kind: AzureSqlFirewallRule metadata: name: sqlf-allowazuresvcaccess spec: diff --git a/config/samples/azure_v1alpha1_sqlserver.yaml b/config/samples/azure_v1alpha1_azuresqlserver.yaml similarity index 76% rename from config/samples/azure_v1alpha1_sqlserver.yaml rename to config/samples/azure_v1alpha1_azuresqlserver.yaml index b92552a3aba..e8fc09db9d3 100644 --- a/config/samples/azure_v1alpha1_sqlserver.yaml +++ b/config/samples/azure_v1alpha1_azuresqlserver.yaml @@ -1,7 +1,7 @@ apiVersion: azure.microsoft.com/v1alpha1 -kind: SqlServer +kind: AzureSqlServer metadata: name: sqlserver-sample-777 spec: - location: "westus" + location: westus resourcegroup: resourcegroup-azure-operators diff --git a/config/samples/azure_v1alpha1_sqlaction.yaml b/config/samples/azure_v1alpha1_sqlaction.yaml deleted file mode 100644 index afe4fa328c0..00000000000 --- a/config/samples/azure_v1alpha1_sqlaction.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: azure.microsoft.com/v1alpha1 -kind: SqlAction -metadata: - name: sqlaction-name -spec: - resourcegroup: resourcegroup-sample-1907 - actionname: rollcreds - servername: sqlserver-sample diff --git a/controllers/sqlaction_controller.go b/controllers/azuresqlaction_controller.go similarity index 78% rename from controllers/sqlaction_controller.go rename to controllers/azuresqlaction_controller.go index f7845b03bf4..dcb3ba8c9e2 100644 --- a/controllers/sqlaction_controller.go +++ b/controllers/azuresqlaction_controller.go @@ -41,25 +41,25 @@ import ( "k8s.io/client-go/tools/record" ) -const sqlActionFinalizerName = "sqlaction.finalizers.azure.com" +const AzureSqlActionFinalizerName = "azuresqlaction.finalizers.azure.com" -// SqlActionReconciler reconciles a SqlAction object -type SqlActionReconciler struct { +// AzureSqlActionReconciler reconciles a AzureSqlAction object +type AzureSqlActionReconciler struct { client.Client Log logr.Logger Recorder record.EventRecorder Scheme *runtime.Scheme } -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqlactions,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqlactions/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqlactions,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqlactions/status,verbs=get;update;patch // Reconcile function runs the actual reconcilation loop of the controller -func (r *SqlActionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { +func (r *AzureSqlActionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { ctx := context.Background() - log := r.Log.WithValues("sqlaction", req.NamespacedName) + log := r.Log.WithValues("azuresqlaction", req.NamespacedName) - var instance azurev1alpha1.SqlAction + var instance azurev1alpha1.AzureSqlAction requeueAfter, err := strconv.Atoi(os.Getenv("REQUEUE_AFTER")) if err != nil { @@ -67,7 +67,7 @@ func (r *SqlActionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { } if err := r.Get(ctx, req.NamespacedName, &instance); err != nil { - log.Info("Unable to fetch SqlAction", "err", err.Error()) + log.Info("Unable to fetch AzureSqlAction", "err", err.Error()) return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -96,16 +96,16 @@ func (r *SqlActionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { } } // TODO: Add error handling for other types of errors we might encounter here - return ctrl.Result{}, fmt.Errorf("error reconciling sqlaction in azure: %v", err) + return ctrl.Result{}, fmt.Errorf("error reconciling azuresqlaction in azure: %v", err) } return ctrl.Result{}, nil } - r.Recorder.Event(&instance, corev1.EventTypeNormal, "Provisioned", "SqlAction "+instance.ObjectMeta.Name+" provisioned ") + r.Recorder.Event(&instance, corev1.EventTypeNormal, "Provisioned", "AzureSqlAction "+instance.ObjectMeta.Name+" provisioned ") return ctrl.Result{}, nil } -func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlAction) error { +func (r *AzureSqlActionReconciler) reconcileExternal(instance *azurev1alpha1.AzureSqlAction) error { ctx := context.Background() serverName := instance.Spec.ServerName groupName := instance.Spec.ResourceGroup @@ -113,7 +113,7 @@ func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlActio instance.Status.Provisioning = true instance.Status.Provisioned = false - instance.Status.Message = "SqlAction in progress" + instance.Status.Message = "AzureSqlAction in progress" // write information back to instance if updateerr := r.Status().Update(ctx, instance); updateerr != nil { r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance") @@ -129,8 +129,8 @@ func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlActio server, err := sdkClient.GetServer() if err != nil { if strings.Contains(err.Error(), "ResourceGroupNotFound") { - r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get instance of SqlServer: Resource group not found") - r.Log.Info("Error", "Unable to get instance of SqlServer: Resource group not found", err) + r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get instance of AzureSqlServer: Resource group not found") + r.Log.Info("Error", "Unable to get instance of AzureSqlServer: Resource group not found", err) instance.Status.Message = "Resource group not found" // write information back to instance if updateerr := r.Status().Update(ctx, instance); updateerr != nil { @@ -138,7 +138,7 @@ func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlActio } return err } else { - r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get instance of SqlServer") + r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get instance of AzureSqlServer") r.Log.Info("Error", "Sql Server instance not found", err) instance.Status.Message = "Sql server instance not found" // write information back to instance @@ -153,16 +153,16 @@ func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlActio // rollcreds action if strings.ToLower(instance.Spec.ActionName) == "rollcreds" { - sqlServerProperties := sql.SQLServerProperties{ + azureSqlServerProperties := sql.SQLServerProperties{ AdministratorLogin: server.ServerProperties.AdministratorLogin, AdministratorLoginPassword: server.ServerProperties.AdministratorLoginPassword, } // Generate a new password newPassword, _ := generateRandomPassword(passwordLength) - sqlServerProperties.AdministratorLoginPassword = to.StringPtr(newPassword) + azureSqlServerProperties.AdministratorLoginPassword = to.StringPtr(newPassword) - if _, err := sdkClient.CreateOrUpdateSQLServer(sqlServerProperties); err != nil { + if _, err := sdkClient.CreateOrUpdateSQLServer(azureSqlServerProperties); err != nil { if !strings.Contains(err.Error(), "not complete") { r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to provision or update instance") return errhelp.NewAzureError(err) @@ -182,7 +182,7 @@ func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlActio _, createOrUpdateSecretErr := controllerutil.CreateOrUpdate(context.Background(), r.Client, secret, func() error { r.Log.Info("Creating or updating secret with SQL Server credentials") - secret.Data["password"] = []byte(*sqlServerProperties.AdministratorLoginPassword) + secret.Data["password"] = []byte(*azureSqlServerProperties.AdministratorLoginPassword) return nil }) if createOrUpdateSecretErr != nil { @@ -192,7 +192,7 @@ func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlActio instance.Status.Provisioning = false instance.Status.Provisioned = true - instance.Status.Message = "SqlAction completed successfully." + instance.Status.Message = "AzureSqlAction completed successfully." // write information back to instance if updateerr := r.Status().Update(ctx, instance); updateerr != nil { @@ -215,13 +215,13 @@ func (r *SqlActionReconciler) reconcileExternal(instance *azurev1alpha1.SqlActio return errors.New("Unknown action name") } - // Add implementations for other SqlActions here (instance.Spec.ActionName) + // Add implementations for other AzureSqlActions here (instance.Spec.ActionName) return nil } -func (r *SqlActionReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *AzureSqlActionReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&azurev1alpha1.SqlAction{}). + For(&azurev1alpha1.AzureSqlAction{}). Complete(r) } diff --git a/controllers/sqldatabase_controller.go b/controllers/azuresqldatabase_controller.go similarity index 71% rename from controllers/sqldatabase_controller.go rename to controllers/azuresqldatabase_controller.go index 1dc848c8a29..de5f2c596b4 100644 --- a/controllers/sqldatabase_controller.go +++ b/controllers/azuresqldatabase_controller.go @@ -37,27 +37,27 @@ import ( azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" ) -const SQLDatabaseFinalizerName = "sqldatabase.finalizers.azure.com" +const azureSQLDatabaseFinalizerName = "azuresqldatabase.finalizers.azure.com" -// SqlDatabaseReconciler reconciles a SqlDatabase object -type SqlDatabaseReconciler struct { +// AzureSqlDatabaseReconciler reconciles a AzureSqlDatabase object +type AzureSqlDatabaseReconciler struct { client.Client Log logr.Logger Recorder record.EventRecorder Scheme *runtime.Scheme } -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqldatabases,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqldatabases/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqldatabases,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqldatabases/status,verbs=get;update;patch -func (r *SqlDatabaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { +func (r *AzureSqlDatabaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { ctx := context.Background() - log := r.Log.WithValues("sqldatabase", req.NamespacedName) + log := r.Log.WithValues("azuresqldatabase", req.NamespacedName) - var instance azurev1alpha1.SqlDatabase + var instance azurev1alpha1.AzureSqlDatabase if err := r.Get(ctx, req.NamespacedName, &instance); err != nil { - log.Info("Unable to retrieve sql-database resource", "err", err.Error()) + log.Info("Unable to retrieve azure-sql-database resource", "err", err.Error()) // we'll ignore not-found errors, since they can't be fixed by an immediate // requeue (we'll need to wait for a new notification), and we can get them // on deleted requests. @@ -65,13 +65,13 @@ func (r *SqlDatabaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) } if helpers.IsBeingDeleted(&instance) { - if helpers.HasFinalizer(&instance, SQLDatabaseFinalizerName) { + if helpers.HasFinalizer(&instance, azureSQLDatabaseFinalizerName) { if err := r.deleteExternal(&instance); err != nil { - log.Info("Delete SqlDatabase failed with ", "err", err.Error()) + log.Info("Delete AzureSqlDatabase failed with ", "err", err.Error()) return ctrl.Result{}, err } - helpers.RemoveFinalizer(&instance, SQLDatabaseFinalizerName) + helpers.RemoveFinalizer(&instance, azureSQLDatabaseFinalizerName) if err := r.Update(context.Background(), &instance); err != nil { return ctrl.Result{}, err } @@ -79,15 +79,15 @@ func (r *SqlDatabaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) return ctrl.Result{}, nil } - if !helpers.HasFinalizer(&instance, SQLDatabaseFinalizerName) { + if !helpers.HasFinalizer(&instance, azureSQLDatabaseFinalizerName) { if err := r.addFinalizer(&instance); err != nil { - log.Info("Adding SqlDatabase finalizer failed with ", "error", err.Error()) + log.Info("Adding AzureSqlDatabase finalizer failed with ", "error", err.Error()) return ctrl.Result{}, err } } if !instance.IsSubmitted() { - r.Recorder.Event(&instance, corev1.EventTypeNormal, "Submitting", "starting resource reconciliation for SqlDatabase") + r.Recorder.Event(&instance, corev1.EventTypeNormal, "Submitting", "starting resource reconciliation for AzureSqlDatabase") if err := r.reconcileExternal(&instance); err != nil { catch := []string{ @@ -102,23 +102,23 @@ func (r *SqlDatabaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, nil } } - return ctrl.Result{}, fmt.Errorf("error reconciling sql database in azure: %v", err) + return ctrl.Result{}, fmt.Errorf("error reconciling azure sql database in azure: %v", err) } return ctrl.Result{}, nil } - r.Recorder.Event(&instance, corev1.EventTypeNormal, "Provisioned", "sqldatabase "+instance.ObjectMeta.Name+" provisioned ") + r.Recorder.Event(&instance, corev1.EventTypeNormal, "Provisioned", "azuresqldatabase "+instance.ObjectMeta.Name+" provisioned ") return ctrl.Result{}, nil } -func (r *SqlDatabaseReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *AzureSqlDatabaseReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&azurev1alpha1.SqlDatabase{}). + For(&azurev1alpha1.AzureSqlDatabase{}). Complete(r) } -func (r *SqlDatabaseReconciler) reconcileExternal(instance *azurev1alpha1.SqlDatabase) error { +func (r *AzureSqlDatabaseReconciler) reconcileExternal(instance *azurev1alpha1.AzureSqlDatabase) error { ctx := context.Background() location := instance.Spec.Location groupName := instance.Spec.ResourceGroup @@ -133,27 +133,27 @@ func (r *SqlDatabaseReconciler) reconcileExternal(instance *azurev1alpha1.SqlDat Location: location, } - sqlDatabaseProperties := sql.SQLDatabaseProperties{ + azureSqlDatabaseProperties := sql.SQLDatabaseProperties{ DatabaseName: dbName, Edition: dbEdition, } - r.Log.Info("Calling createorupdate SQL database") + r.Log.Info("Calling createorupdate Azure SQL database") // instance.Status.Provisioning = true - //get owner instance of SqlServer - r.Recorder.Event(instance, corev1.EventTypeNormal, "UpdatingOwner", "Updating owner SqlServer instance") - var ownerInstance azurev1alpha1.SqlServer - sqlServerNamespacedName := types.NamespacedName{Name: server, Namespace: instance.Namespace} - err := r.Get(ctx, sqlServerNamespacedName, &ownerInstance) + //get owner instance of AzureSqlServer + r.Recorder.Event(instance, corev1.EventTypeNormal, "UpdatingOwner", "Updating owner AzureSqlServer instance") + var ownerInstance azurev1alpha1.AzureSqlServer + azureSqlServerNamespacedName := types.NamespacedName{Name: server, Namespace: instance.Namespace} + err := r.Get(ctx, azureSqlServerNamespacedName, &ownerInstance) if err != nil { //log error and kill it, as the parent might not exist in the cluster. It could have been created elsewhere or through the portal directly - r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get owner instance of SqlServer") + r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get owner instance of AzureSqlServer") } else { r.Recorder.Event(instance, corev1.EventTypeNormal, "OwnerAssign", "Got owner instance of Sql Server and assigning controller reference now") innerErr := controllerutil.SetControllerReference(&ownerInstance, instance, r.Scheme) if innerErr != nil { - r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to set controller reference to SqlServer") + r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to set controller reference to AzureSqlServer") } r.Recorder.Event(instance, corev1.EventTypeNormal, "OwnerAssign", "Owner instance assigned successfully") } @@ -163,7 +163,7 @@ func (r *SqlDatabaseReconciler) reconcileExternal(instance *azurev1alpha1.SqlDat r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance") } - _, err = sdkClient.CreateOrUpdateDB(sqlDatabaseProperties) + _, err = sdkClient.CreateOrUpdateDB(azureSqlDatabaseProperties) if err != nil { if errhelp.IsAsynchronousOperationNotComplete(err) || errhelp.IsGroupNotFound(err) { r.Log.Info("Async operation not complete or group not found") @@ -191,7 +191,7 @@ func (r *SqlDatabaseReconciler) reconcileExternal(instance *azurev1alpha1.SqlDat return nil } -func (r *SqlDatabaseReconciler) deleteExternal(instance *azurev1alpha1.SqlDatabase) error { +func (r *AzureSqlDatabaseReconciler) deleteExternal(instance *azurev1alpha1.AzureSqlDatabase) error { ctx := context.Background() location := instance.Spec.Location groupName := instance.Spec.ResourceGroup @@ -221,12 +221,12 @@ func (r *SqlDatabaseReconciler) deleteExternal(instance *azurev1alpha1.SqlDataba return nil } -func (r *SqlDatabaseReconciler) addFinalizer(instance *azurev1alpha1.SqlDatabase) error { - helpers.AddFinalizer(instance, SQLDatabaseFinalizerName) +func (r *AzureSqlDatabaseReconciler) addFinalizer(instance *azurev1alpha1.AzureSqlDatabase) error { + helpers.AddFinalizer(instance, azureSQLDatabaseFinalizerName) err := r.Update(context.Background(), instance) if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, corev1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", SQLDatabaseFinalizerName)) + r.Recorder.Event(instance, corev1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", azureSQLDatabaseFinalizerName)) return nil } diff --git a/controllers/sqlfirewallrule_controller.go b/controllers/azuresqlfirewallrule_controller.go similarity index 70% rename from controllers/sqlfirewallrule_controller.go rename to controllers/azuresqlfirewallrule_controller.go index 591b354cc92..5219349123b 100644 --- a/controllers/sqlfirewallrule_controller.go +++ b/controllers/azuresqlfirewallrule_controller.go @@ -35,28 +35,28 @@ import ( azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" ) -const SQLFirewallRuleFinalizerName = "sqlfirewallrule.finalizers.azure.com" +const azureSQLFirewallRuleFinalizerName = "azuresqlfirewallrule.finalizers.azure.com" -// SqlFirewallRuleReconciler reconciles a SqlFirewallRule object -type SqlFirewallRuleReconciler struct { +// AzureSqlFirewallRuleReconciler reconciles a AzureSqlFirewallRule object +type AzureSqlFirewallRuleReconciler struct { client.Client Log logr.Logger Recorder record.EventRecorder Scheme *runtime.Scheme } -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqlfirewallrules,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqlfirewallrules/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqlfirewallrules,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqlfirewallrules/status,verbs=get;update;patch -func (r *SqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { +func (r *AzureSqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { ctx := context.Background() - log := r.Log.WithValues("sqlfirewallrule", req.NamespacedName) + log := r.Log.WithValues("azuresqlfirewallrule", req.NamespacedName) // your logic here - var instance azurev1alpha1.SqlFirewallRule + var instance azurev1alpha1.AzureSqlFirewallRule if err := r.Get(ctx, req.NamespacedName, &instance); err != nil { - log.Info("Unable to retrieve sql-firewall-rule resource", "err", err.Error()) + log.Info("Unable to retrieve azure-sql-firewall-rule resource", "err", err.Error()) // we'll ignore not-found errors, since they can't be fixed by an immediate // requeue (we'll need to wait for a new notification), and we can get them // on deleted requests. @@ -64,13 +64,13 @@ func (r *SqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Result, er } if helpers.IsBeingDeleted(&instance) { - if helpers.HasFinalizer(&instance, SQLFirewallRuleFinalizerName) { + if helpers.HasFinalizer(&instance, azureSQLFirewallRuleFinalizerName) { if err := r.deleteExternal(&instance); err != nil { - log.Info("Delete SqlFirewallRule failed with ", "error", err.Error()) + log.Info("Delete AzureSqlFirewallRule failed with ", "error", err.Error()) return ctrl.Result{}, err } - helpers.RemoveFinalizer(&instance, SQLFirewallRuleFinalizerName) + helpers.RemoveFinalizer(&instance, azureSQLFirewallRuleFinalizerName) if err := r.Update(context.Background(), &instance); err != nil { return ctrl.Result{}, err } @@ -78,15 +78,15 @@ func (r *SqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Result, er return ctrl.Result{}, nil } - if !helpers.HasFinalizer(&instance, SQLFirewallRuleFinalizerName) { + if !helpers.HasFinalizer(&instance, azureSQLFirewallRuleFinalizerName) { if err := r.addFinalizer(&instance); err != nil { - log.Info("Adding SqlFirewallRule finalizer failed with ", "error", err.Error()) + log.Info("Adding AzureSqlFirewallRule finalizer failed with ", "error", err.Error()) return ctrl.Result{}, err } } if !instance.IsSubmitted() { - r.Recorder.Event(&instance, corev1.EventTypeNormal, "Submitting", "starting resource reconciliation for SqlFirewallRule") + r.Recorder.Event(&instance, corev1.EventTypeNormal, "Submitting", "starting resource reconciliation for AzureSqlFirewallRule") if err := r.reconcileExternal(&instance); err != nil { catch := []string{ @@ -101,23 +101,23 @@ func (r *SqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Result, er return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, nil } } - return ctrl.Result{}, fmt.Errorf("error reconciling sql firewall rule in azure: %v", err) + return ctrl.Result{}, fmt.Errorf("error reconciling azure sql firewall rule in azure: %v", err) } return ctrl.Result{}, nil } - r.Recorder.Event(&instance, corev1.EventTypeNormal, "Provisioned", "sqlfirewallrule "+instance.ObjectMeta.Name+" provisioned ") + r.Recorder.Event(&instance, corev1.EventTypeNormal, "Provisioned", "azuresqlfirewallrule "+instance.ObjectMeta.Name+" provisioned ") return ctrl.Result{}, nil } -func (r *SqlFirewallRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *AzureSqlFirewallRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&azurev1alpha1.SqlFirewallRule{}). + For(&azurev1alpha1.AzureSqlFirewallRule{}). Complete(r) } -func (r *SqlFirewallRuleReconciler) reconcileExternal(instance *azurev1alpha1.SqlFirewallRule) error { +func (r *AzureSqlFirewallRuleReconciler) reconcileExternal(instance *azurev1alpha1.AzureSqlFirewallRule) error { ctx := context.Background() groupName := instance.Spec.ResourceGroup server := instance.Spec.Server @@ -131,21 +131,21 @@ func (r *SqlFirewallRuleReconciler) reconcileExternal(instance *azurev1alpha1.Sq ServerName: server, } - r.Log.Info("Calling createorupdate SQL firewall rule") + r.Log.Info("Calling createorupdate Azure SQL firewall rule") - //get owner instance of SqlServer - r.Recorder.Event(instance, corev1.EventTypeNormal, "UpdatingOwner", "Updating owner SqlServer instance") - var ownerInstance azurev1alpha1.SqlServer - sqlServerNamespacedName := types.NamespacedName{Name: server, Namespace: instance.Namespace} - err := r.Get(ctx, sqlServerNamespacedName, &ownerInstance) + //get owner instance of AzureSqlServer + r.Recorder.Event(instance, corev1.EventTypeNormal, "UpdatingOwner", "Updating owner AzureSqlServer instance") + var ownerInstance azurev1alpha1.AzureSqlServer + azureSqlServerNamespacedName := types.NamespacedName{Name: server, Namespace: instance.Namespace} + err := r.Get(ctx, azureSqlServerNamespacedName, &ownerInstance) if err != nil { //log error and kill it, as the parent might not exist in the cluster. It could have been created elsewhere or through the portal directly - r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get owner instance of SqlServer") + r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to get owner instance of AzureSqlServer") } else { r.Recorder.Event(instance, corev1.EventTypeNormal, "OwnerAssign", "Got owner instance of Sql Server and assigning controller reference now") innerErr := controllerutil.SetControllerReference(&ownerInstance, instance, r.Scheme) if innerErr != nil { - r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to set controller reference to SqlServer") + r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to set controller reference to AzureSqlServer") } r.Recorder.Event(instance, corev1.EventTypeNormal, "OwnerAssign", "Owner instance assigned successfully") } @@ -183,7 +183,7 @@ func (r *SqlFirewallRuleReconciler) reconcileExternal(instance *azurev1alpha1.Sq return nil } -func (r *SqlFirewallRuleReconciler) deleteExternal(instance *azurev1alpha1.SqlFirewallRule) error { +func (r *AzureSqlFirewallRuleReconciler) deleteExternal(instance *azurev1alpha1.AzureSqlFirewallRule) error { ctx := context.Background() groupName := instance.Spec.ResourceGroup server := instance.Spec.Server @@ -211,12 +211,12 @@ func (r *SqlFirewallRuleReconciler) deleteExternal(instance *azurev1alpha1.SqlFi return nil } -func (r *SqlFirewallRuleReconciler) addFinalizer(instance *azurev1alpha1.SqlFirewallRule) error { - helpers.AddFinalizer(instance, SQLFirewallRuleFinalizerName) +func (r *AzureSqlFirewallRuleReconciler) addFinalizer(instance *azurev1alpha1.AzureSqlFirewallRule) error { + helpers.AddFinalizer(instance, azureSQLFirewallRuleFinalizerName) err := r.Update(context.Background(), instance) if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, corev1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", SQLFirewallRuleFinalizerName)) + r.Recorder.Event(instance, corev1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", azureSQLFirewallRuleFinalizerName)) return nil } diff --git a/controllers/sqlserver_controller.go b/controllers/azuresqlserver_controller.go similarity index 86% rename from controllers/sqlserver_controller.go rename to controllers/azuresqlserver_controller.go index fd4034711e8..471a8b8384b 100644 --- a/controllers/sqlserver_controller.go +++ b/controllers/azuresqlserver_controller.go @@ -40,8 +40,8 @@ import ( "k8s.io/apimachinery/pkg/types" ) -// SqlServerReconciler reconciles a SqlServer object -type SqlServerReconciler struct { +// AzureSqlServerReconciler reconciles an AzureSqlServer object +type AzureSqlServerReconciler struct { client.Client Log logr.Logger Recorder record.EventRecorder @@ -56,13 +56,13 @@ const maxUsernameAllowedLength = 63 const minPasswordAllowedLength = 8 const maxPasswordAllowedLength = 128 -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqlservers,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=azure.microsoft.com,resources=sqlservers/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqlservers,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqlservers/status,verbs=get;update;patch -func (r *SqlServerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { +func (r *AzureSqlServerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { ctx := context.Background() - log := r.Log.WithValues("sqlserver", req.NamespacedName) - var instance azurev1alpha1.SqlServer + log := r.Log.WithValues("azuresqlserver", req.NamespacedName) + var instance azurev1alpha1.AzureSqlServer if err := r.Get(ctx, req.NamespacedName, &instance); err != nil { log.Info("Unable to retrieve sql-server resource", "err", err.Error()) @@ -73,7 +73,7 @@ func (r *SqlServerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { } if helpers.IsBeingDeleted(&instance) { - if helpers.HasFinalizer(&instance, SQLServerFinalizerName) { + if helpers.HasFinalizer(&instance, AzureSQLServerFinalizerName) { if err := r.deleteExternal(&instance); err != nil { catch := []string{ errhelp.AsyncOpIncompleteError, @@ -84,12 +84,12 @@ func (r *SqlServerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, nil } } - log.Info("Delete SqlServer failed with ", "error", err.Error()) + log.Info("Delete AzureSqlServer failed with ", "error", err.Error()) return ctrl.Result{}, err } - helpers.RemoveFinalizer(&instance, SQLServerFinalizerName) + helpers.RemoveFinalizer(&instance, AzureSQLServerFinalizerName) if err := r.Update(context.Background(), &instance); err != nil { return ctrl.Result{}, err } @@ -97,9 +97,9 @@ func (r *SqlServerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return ctrl.Result{}, nil } - if !helpers.HasFinalizer(&instance, SQLServerFinalizerName) { + if !helpers.HasFinalizer(&instance, AzureSQLServerFinalizerName) { if err := r.addFinalizer(&instance); err != nil { - log.Info("Adding SqlServer finalizer failed with ", "error", err.Error()) + log.Info("Adding AzureSqlServer finalizer failed with ", "error", err.Error()) return ctrl.Result{}, err } } @@ -171,17 +171,17 @@ func (r *SqlServerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return ctrl.Result{}, fmt.Errorf("error verifying sql server in azure: %v", err) } - r.Recorder.Event(&instance, v1.EventTypeNormal, "Provisioned", "sqlserver "+instance.ObjectMeta.Name+" provisioned ") + r.Recorder.Event(&instance, v1.EventTypeNormal, "Provisioned", "azuresqlserver "+instance.ObjectMeta.Name+" provisioned ") return ctrl.Result{}, nil } -func (r *SqlServerReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *AzureSqlServerReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&azurev1alpha1.SqlServer{}). + For(&azurev1alpha1.AzureSqlServer{}). Complete(r) } -func (r *SqlServerReconciler) reconcileExternal(instance *azurev1alpha1.SqlServer) error { +func (r *AzureSqlServerReconciler) reconcileExternal(instance *azurev1alpha1.AzureSqlServer) error { ctx := context.Background() location := instance.Spec.Location name := instance.ObjectMeta.Name @@ -196,14 +196,14 @@ func (r *SqlServerReconciler) reconcileExternal(instance *azurev1alpha1.SqlServe // Check to see if secret already exists for admin username/password secret, _ := r.GetOrPrepareSecret(instance) - sqlServerProperties := sql.SQLServerProperties{ + azureSqlServerProperties := sql.SQLServerProperties{ AdministratorLogin: to.StringPtr(string(secret.Data["username"])), AdministratorLoginPassword: to.StringPtr(string(secret.Data["password"])), } // create the sql server instance.Status.Provisioning = true - if _, err := sdkClient.CreateOrUpdateSQLServer(sqlServerProperties); err != nil { + if _, err := sdkClient.CreateOrUpdateSQLServer(azureSqlServerProperties); err != nil { if !strings.Contains(err.Error(), "not complete") { instance.Status.Message = fmt.Sprintf("CreateOrUpdateSQLServer not complete: %v", err) @@ -245,7 +245,7 @@ func (r *SqlServerReconciler) reconcileExternal(instance *azurev1alpha1.SqlServe return nil } -func (r *SqlServerReconciler) verifyExternal(instance *azurev1alpha1.SqlServer) error { +func (r *AzureSqlServerReconciler) verifyExternal(instance *azurev1alpha1.AzureSqlServer) error { ctx := context.Background() location := instance.Spec.Location name := instance.ObjectMeta.Name @@ -275,7 +275,7 @@ func (r *SqlServerReconciler) verifyExternal(instance *azurev1alpha1.SqlServer) if instance.Status.State == "Ready" { instance.Status.Provisioned = true instance.Status.Provisioning = false - instance.Status.Message = "SqlServer successfully provisioned" + instance.Status.Message = "AzureSqlServer successfully provisioned" } // write information back to instance @@ -287,7 +287,7 @@ func (r *SqlServerReconciler) verifyExternal(instance *azurev1alpha1.SqlServer) return errhelp.NewAzureError(err) } -func (r *SqlServerReconciler) deleteExternal(instance *azurev1alpha1.SqlServer) error { +func (r *AzureSqlServerReconciler) deleteExternal(instance *azurev1alpha1.AzureSqlServer) error { ctx := context.Background() name := instance.ObjectMeta.Name groupName := instance.Spec.ResourceGroup @@ -314,7 +314,7 @@ func (r *SqlServerReconciler) deleteExternal(instance *azurev1alpha1.SqlServer) return nil } -func (r *SqlServerReconciler) GetOrPrepareSecret(instance *azurev1alpha1.SqlServer) (*v1.Secret, error) { +func (r *AzureSqlServerReconciler) GetOrPrepareSecret(instance *azurev1alpha1.AzureSqlServer) (*v1.Secret, error) { name := instance.ObjectMeta.Name secret := &v1.Secret{ @@ -327,7 +327,7 @@ func (r *SqlServerReconciler) GetOrPrepareSecret(instance *azurev1alpha1.SqlServ "username": []byte(""), "fullyqualifiedusername": []byte(""), "password": []byte(""), - "sqlservername": []byte(""), + "azuresqlservername": []byte(""), "fullyqualifiedservername": []byte(""), }, Type: "Opaque", @@ -345,13 +345,13 @@ func (r *SqlServerReconciler) GetOrPrepareSecret(instance *azurev1alpha1.SqlServ usernameSuffix := "@" + name servernameSuffix := ".database.windows.net" - fullyQualifiedAdminUsername := randomUsername + usernameSuffix // "@"" - fullyQualifiedServername := name + servernameSuffix // ".database.windows.net" + fullyQualifiedAdminUsername := randomUsername + usernameSuffix // "@"" + fullyQualifiedServername := name + servernameSuffix // ".database.windows.net" secret.Data["username"] = []byte(randomUsername) secret.Data["fullyqualifiedusername"] = []byte(fullyQualifiedAdminUsername) secret.Data["password"] = []byte(randomPassword) - secret.Data["sqlservername"] = []byte(name) + secret.Data["azuresqlservername"] = []byte(name) secret.Data["fullyqualifiedservername"] = []byte(fullyQualifiedServername) if err := r.Get(context.Background(), types.NamespacedName{Name: name, Namespace: instance.Namespace}, secret); err == nil { diff --git a/controllers/sqlserver_controller_finalizer.go b/controllers/azuresqlserver_controller_finalizer.go similarity index 77% rename from controllers/sqlserver_controller_finalizer.go rename to controllers/azuresqlserver_controller_finalizer.go index e232f142fa1..d1fabae3029 100644 --- a/controllers/sqlserver_controller_finalizer.go +++ b/controllers/azuresqlserver_controller_finalizer.go @@ -24,13 +24,13 @@ import ( helpers "github.com/Azure/azure-service-operator/pkg/helpers" ) -const SQLServerFinalizerName = "sqlserver.finalizers.azure.com" +const AzureSQLServerFinalizerName = "azuresqlserver.finalizers.azure.com" -func (r *SqlServerReconciler) addFinalizer(instance *azurev1alpha1.SqlServer) error { - helpers.AddFinalizer(instance, SQLServerFinalizerName) +func (r *AzureSqlServerReconciler) addFinalizer(instance *azurev1alpha1.AzureSqlServer) error { + helpers.AddFinalizer(instance, AzureSQLServerFinalizerName) if updateerr := r.Update(context.Background(), instance); updateerr != nil { r.Recorder.Event(instance, "Warning", "Failed", "Failed to update finalizer") } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", SQLServerFinalizerName)) + r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", AzureSQLServerFinalizerName)) return nil } diff --git a/main.go b/main.go index 784869e147e..ced53bce116 100644 --- a/main.go +++ b/main.go @@ -171,25 +171,25 @@ func main() { os.Exit(1) } - if err = (&controllers.SqlServerReconciler{ + if err = (&controllers.AzureSqlServerReconciler{ Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controllers").WithName("SqlServer"), - Recorder: mgr.GetEventRecorderFor("SqlServer-controller"), + Log: ctrl.Log.WithName("controllers").WithName("AzureSqlServer"), + Recorder: mgr.GetEventRecorderFor("AzureSqlServer-controller"), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "SqlServer") + setupLog.Error(err, "unable to create controller", "controller", "AzureSqlServer") os.Exit(1) } - if err = (&controllers.SqlDatabaseReconciler{ + if err = (&controllers.AzureSqlDatabaseReconciler{ Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controllers").WithName("SqlDatabase"), - Recorder: mgr.GetEventRecorderFor("SqlDatabase-controller"), + Log: ctrl.Log.WithName("controllers").WithName("AzureSqlDatabase"), + Recorder: mgr.GetEventRecorderFor("AzureSqlDatabase-controller"), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "SqlDatabase") + setupLog.Error(err, "unable to create controller", "controller", "AzureSqlDatabase") os.Exit(1) } - if err = (&controllers.SqlFirewallRuleReconciler{ + if err = (&controllers.AzureSqlFirewallRuleReconciler{ Client: mgr.GetClient(), Log: ctrl.Log.WithName("controllers").WithName("SqlFirewallRule"), Recorder: mgr.GetEventRecorderFor("SqlFirewallRule-controller"), @@ -198,13 +198,13 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "SqlFirewallRule") os.Exit(1) } - if err = (&controllers.SqlActionReconciler{ + if err = (&controllers.AzureSqlActionReconciler{ Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controllers").WithName("SqlAction"), - Recorder: mgr.GetEventRecorderFor("SqlAction-controller"), + Log: ctrl.Log.WithName("controllers").WithName("AzureSqlAction"), + Recorder: mgr.GetEventRecorderFor("AzureSqlAction-controller"), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "SqlAction") + setupLog.Error(err, "unable to create controller", "controller", "AzureSqlAction") os.Exit(1) }