Skip to content

Commit

Permalink
base mysql version addition
Browse files Browse the repository at this point in the history
  • Loading branch information
frodopwns committed May 13, 2020
1 parent 86b9328 commit 9c93e7e
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 6 deletions.
12 changes: 7 additions & 5 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -116,4 +115,7 @@ resources:
- group: azure
kind: BlobContainer
version: v1alpha2
- group: azure
kind: MySQLServer
version: v1alpha2
version: "2"
6 changes: 6 additions & 0 deletions api/v1alpha1/mysqlserver_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha1

func (*MySQLServer) Hub() {}
1 change: 1 addition & 0 deletions api/v1alpha1/mysqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/mysqlserver_webhook.go
Original file line number Diff line number Diff line change
@@ -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!
57 changes: 57 additions & 0 deletions api/v1alpha2/mysqlserver_conversion.go
Original file line number Diff line number Diff line change
@@ -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

}
104 changes: 104 additions & 0 deletions api/v1alpha2/mysqlserver_types.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
}
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions config/default/manager_image_patch.yaml-e
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 24 additions & 0 deletions config/rbac/mysqlserver_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions config/rbac/mysqlserver_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9c93e7e

Please sign in to comment.