From 9c93e7e77c7141bdd854c93042b0630517dd87ea Mon Sep 17 00:00:00 2001 From: Erin Corson Date: Mon, 11 May 2020 21:07:16 -0600 Subject: [PATCH] base mysql version addition --- PROJECT | 12 +-- api/v1alpha1/mysqlserver_conversion.go | 6 ++ api/v1alpha1/mysqlserver_types.go | 1 + api/v1alpha1/mysqlserver_webhook.go | 20 +++++ api/v1alpha2/mysqlserver_conversion.go | 57 ++++++++++++ api/v1alpha2/mysqlserver_types.go | 104 ++++++++++++++++++++++ config/default/manager_image_patch.yaml | 2 +- config/default/manager_image_patch.yaml-e | 56 ++++++++++++ config/rbac/mysqlserver_editor_role.yaml | 24 +++++ config/rbac/mysqlserver_viewer_role.yaml | 20 +++++ go.sum | 5 ++ main.go | 5 ++ 12 files changed, 306 insertions(+), 6 deletions(-) create mode 100644 api/v1alpha1/mysqlserver_conversion.go create mode 100644 api/v1alpha1/mysqlserver_webhook.go create mode 100644 api/v1alpha2/mysqlserver_conversion.go create mode 100644 api/v1alpha2/mysqlserver_types.go create mode 100644 config/default/manager_image_patch.yaml-e create mode 100644 config/rbac/mysqlserver_editor_role.yaml create mode 100644 config/rbac/mysqlserver_viewer_role.yaml diff --git a/PROJECT b/PROJECT index 1a340ea02a3..10b8f58785a 100644 --- a/PROJECT +++ b/PROJECT @@ -47,9 +47,8 @@ resources: kind: PostgreSQLDatabase version: v1alpha1 - group: azure - kind: PostgreSQLFirewallRule - version: v1alpha1 kind: PostgreSQLVNetRule + version: v1alpha1 - group: azure kind: PostgreSQLVNetRule version: v1alpha1 @@ -93,14 +92,14 @@ resources: kind: AzureVirtualMachine version: v1alpha1 - group: azure - version: v1alpha1 kind: AzureSQLManagedUser -- group: azure version: v1alpha1 - kind: AzureLoadBalancer - group: azure + kind: AzureLoadBalancer version: v1alpha1 +- group: azure kind: AzureVMScaleSet + version: v1alpha1 - group: azure kind: AzureSqlServer version: v1beta1 @@ -116,4 +115,7 @@ resources: - group: azure kind: BlobContainer version: v1alpha2 +- group: azure + kind: MySQLServer + version: v1alpha2 version: "2" diff --git a/api/v1alpha1/mysqlserver_conversion.go b/api/v1alpha1/mysqlserver_conversion.go new file mode 100644 index 00000000000..1ffb0602e15 --- /dev/null +++ b/api/v1alpha1/mysqlserver_conversion.go @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package v1alpha1 + +func (*MySQLServer) Hub() {} diff --git a/api/v1alpha1/mysqlserver_types.go b/api/v1alpha1/mysqlserver_types.go index 25a24adbf30..c0377d72952 100644 --- a/api/v1alpha1/mysqlserver_types.go +++ b/api/v1alpha1/mysqlserver_types.go @@ -24,6 +24,7 @@ type MySQLServerSpec struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status +// +kubebuilder:storageversion // MySQLServer is the Schema for the mysqlservers API // +kubebuilder:printcolumn:name="Provisioned",type="string",JSONPath=".status.provisioned" diff --git a/api/v1alpha1/mysqlserver_webhook.go b/api/v1alpha1/mysqlserver_webhook.go new file mode 100644 index 00000000000..b450eae334c --- /dev/null +++ b/api/v1alpha1/mysqlserver_webhook.go @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package v1alpha1 + +import ( + ctrl "sigs.k8s.io/controller-runtime" + logf "sigs.k8s.io/controller-runtime/pkg/log" +) + +// log is for logging in this package. +var mysqlserverlog = logf.Log.WithName("mysqlserver-resource") + +func (r *MySQLServer) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! diff --git a/api/v1alpha2/mysqlserver_conversion.go b/api/v1alpha2/mysqlserver_conversion.go new file mode 100644 index 00000000000..b372408eea7 --- /dev/null +++ b/api/v1alpha2/mysqlserver_conversion.go @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package v1alpha2 + +import ( + "github.com/Azure/azure-service-operator/api/v1alpha1" + "sigs.k8s.io/controller-runtime/pkg/conversion" +) + +func (src *MySQLServer) ConvertTo(dstRaw conversion.Hub) error { + dst := dstRaw.(*v1alpha1.MySQLServer) + + // ObjectMeta + dst.ObjectMeta = src.ObjectMeta + + // Spec + dst.Spec.ResourceGroup = src.Spec.ResourceGroup + dst.Spec.Location = src.Spec.Location + dst.Spec.Sku = src.Spec.Sku + dst.Spec.ServerVersion = src.Spec.ServerVersion + dst.Spec.SSLEnforcement = src.Spec.SSLEnforcement + dst.Spec.CreateMode = src.Spec.CreateMode + dst.Spec.ReplicaProperties = src.Spec.ReplicaProperties + dst.Spec.KeyVaultToStoreSecrets = src.Spec.KeyVaultToStoreSecrets + + // New Spec + //dst.Spec.StorageProfile = nil + + // Status + dst.Status = src.Status + + return nil +} + +func (dst *MySQLServer) ConvertFrom(srcRaw conversion.Hub) error { + src := srcRaw.(*v1alpha1.MySQLServer) + + // ObjectMeta + dst.ObjectMeta = src.ObjectMeta + + // Spec + dst.Spec.ResourceGroup = src.Spec.ResourceGroup + dst.Spec.Location = src.Spec.Location + dst.Spec.Sku = src.Spec.Sku + dst.Spec.ServerVersion = src.Spec.ServerVersion + dst.Spec.SSLEnforcement = src.Spec.SSLEnforcement + dst.Spec.CreateMode = src.Spec.CreateMode + dst.Spec.ReplicaProperties = src.Spec.ReplicaProperties + dst.Spec.KeyVaultToStoreSecrets = src.Spec.KeyVaultToStoreSecrets + + // Status + dst.Status = src.Status + + return nil + +} diff --git a/api/v1alpha2/mysqlserver_types.go b/api/v1alpha2/mysqlserver_types.go new file mode 100644 index 00000000000..7376e46d5be --- /dev/null +++ b/api/v1alpha2/mysqlserver_types.go @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package v1alpha2 + +import ( + "github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql" + "github.com/Azure/azure-service-operator/api/v1alpha1" + 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. + +type StorageProfile struct { + // BackupRetentionDays - Backup retention days for the server. + BackupRetentionDays *int32 `json:"backupRetentionDays,omitempty"` + // GeoRedundantBackup - Enable Geo-redundant or not for server backup. Possible values include: 'Enabled', 'Disabled' + GeoRedundantBackup mysql.GeoRedundantBackup `json:"geoRedundantBackup,omitempty"` + // StorageMB - Max storage allowed for a server. + StorageMB *int32 `json:"storageMB,omitempty"` + // StorageAutogrow - Enable Storage Auto Grow. Possible values include: 'StorageAutogrowEnabled', 'StorageAutogrowDisabled' + StorageAutogrow mysql.StorageAutogrow `json:"storageAutogrow,omitempty"` +} + +// MySQLServerSpec defines the desired state of MySQLServer +type MySQLServerSpec struct { + Location string `json:"location"` + ResourceGroup string `json:"resourceGroup,omitempty"` + Sku v1alpha1.AzureDBsSQLSku `json:"sku,omitempty"` + ServerVersion v1alpha1.ServerVersion `json:"serverVersion,omitempty"` + SSLEnforcement v1alpha1.SslEnforcementEnum `json:"sslEnforcement,omitempty"` + CreateMode string `json:"createMode,omitempty"` + ReplicaProperties v1alpha1.ReplicaProperties `json:"replicaProperties,omitempty"` + StorageProfile *StorageProfile `json:"storageProfile,omitempty"` + KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status + +// MySQLServer is the Schema for the mysqlservers API +// +kubebuilder:printcolumn:name="Provisioned",type="string",JSONPath=".status.provisioned" +// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message" +type MySQLServer struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec MySQLServerSpec `json:"spec,omitempty"` + Status v1alpha1.ASOStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// MySQLServerList contains a list of MySQLServer +type MySQLServerList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []MySQLServer `json:"items"` +} + +func init() { + SchemeBuilder.Register(&MySQLServer{}, &MySQLServerList{}) +} + +func NewDefaultMySQLServer(name, resourceGroup, location string) *MySQLServer { + return &MySQLServer{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: "default", + }, + Spec: MySQLServerSpec{ + Location: location, + ResourceGroup: resourceGroup, + Sku: v1alpha1.AzureDBsSQLSku{ + Name: "GP_Gen5_4", + Tier: v1alpha1.SkuTier("GeneralPurpose"), + Family: "Gen5", + Size: "51200", + Capacity: 4, + }, + ServerVersion: v1alpha1.ServerVersion("8.0"), + SSLEnforcement: v1alpha1.SslEnforcementEnumEnabled, + CreateMode: "Default", + }, + } +} + +func NewReplicaMySQLServer(name, resourceGroup, location string, sourceserverid string) *MySQLServer { + return &MySQLServer{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: "default", + }, + Spec: MySQLServerSpec{ + Location: location, + ResourceGroup: resourceGroup, + CreateMode: "Replica", + ReplicaProperties: v1alpha1.ReplicaProperties{ + SourceServerId: sourceserverid, + }, + }, + } +} diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index 4a3ddd7410b..ce0de47caca 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -8,7 +8,7 @@ spec: spec: containers: # Change the value of image field below to your controller image URL - - image: controller:latest + - image: docker.io/frodopwns/op6:4 name: manager env: - name: AZURE_CLIENT_ID diff --git a/config/default/manager_image_patch.yaml-e b/config/default/manager_image_patch.yaml-e new file mode 100644 index 00000000000..4a3ddd7410b --- /dev/null +++ b/config/default/manager_image_patch.yaml-e @@ -0,0 +1,56 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + # Change the value of image field below to your controller image URL + - image: controller:latest + name: manager + env: + - name: AZURE_CLIENT_ID + valueFrom: + secretKeyRef: + name: azureoperatorsettings + key: AZURE_CLIENT_ID + optional: true + - name: AZURE_CLIENT_SECRET + valueFrom: + secretKeyRef: + name: azureoperatorsettings + key: AZURE_CLIENT_SECRET + optional: true + - name: AZURE_TENANT_ID + valueFrom: + secretKeyRef: + name: azureoperatorsettings + key: AZURE_TENANT_ID + - name: AZURE_SUBSCRIPTION_ID + valueFrom: + secretKeyRef: + name: azureoperatorsettings + key: AZURE_SUBSCRIPTION_ID + - name: AZURE_USE_MI + valueFrom: + secretKeyRef: + name: azureoperatorsettings + key: AZURE_USE_MI + optional: true + - name: AZURE_OPERATOR_KEYVAULT + valueFrom: + secretKeyRef: + name: azureoperatorsettings + key: AZURE_OPERATOR_KEYVAULT + optional: true + - name: AZURE_CLOUD_ENV + valueFrom: + secretKeyRef: + key: AZURE_CLOUD_ENV + name: azureoperatorsettings + optional: true + #requeue after time in seconds" + - name: REQUEUE_AFTER + value: "30" diff --git a/config/rbac/mysqlserver_editor_role.yaml b/config/rbac/mysqlserver_editor_role.yaml new file mode 100644 index 00000000000..5ce31344d33 --- /dev/null +++ b/config/rbac/mysqlserver_editor_role.yaml @@ -0,0 +1,24 @@ +# permissions for end users to edit mysqlservers. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: mysqlserver-editor-role +rules: +- apiGroups: + - azure.microsoft.com + resources: + - mysqlservers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - azure.microsoft.com + resources: + - mysqlservers/status + verbs: + - get diff --git a/config/rbac/mysqlserver_viewer_role.yaml b/config/rbac/mysqlserver_viewer_role.yaml new file mode 100644 index 00000000000..ed5932a047c --- /dev/null +++ b/config/rbac/mysqlserver_viewer_role.yaml @@ -0,0 +1,20 @@ +# permissions for end users to view mysqlservers. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: mysqlserver-viewer-role +rules: +- apiGroups: + - azure.microsoft.com + resources: + - mysqlservers + verbs: + - get + - list + - watch +- apiGroups: + - azure.microsoft.com + resources: + - mysqlservers/status + verbs: + - get diff --git a/go.sum b/go.sum index 24a2ed91b3c..f76b9eb8bff 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,7 @@ github.com/Azure/go-autorest/tracing v0.1.0 h1:TRBxC5Pj/fIuh4Qob0ZpkggbfT8RC0Sub github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88= github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= @@ -233,6 +234,7 @@ github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTV github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk= github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU= github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= @@ -284,6 +286,7 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -418,7 +421,9 @@ github.com/sethvargo/go-password v0.1.2/go.mod h1:qKHfdSjT26DpHQWHWWR5+X4BI45jT3 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= diff --git a/main.go b/main.go index 0b02b54f8be..4ee5f851f0a 100644 --- a/main.go +++ b/main.go @@ -774,6 +774,11 @@ func main() { setupLog.Error(err, "unable to create webhook", "webhook", "BlobContainer") os.Exit(1) } + + if err = (&azurev1alpha1.MySQLServer{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "MySQLServer") + os.Exit(1) + } // +kubebuilder:scaffold:builder setupLog.Info("starting manager")