Skip to content

Commit

Permalink
v1beta1 for azure sql failover groups
Browse files Browse the repository at this point in the history
  • Loading branch information
frodopwns committed May 6, 2020
1 parent ac997f6 commit 2ce8469
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 4 deletions.
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ resources:
- group: azure
kind: AzureSqlFirewallRule
version: v1beta1
- group: azure
kind: AzureSqlFailoverGroup
version: v1beta1
version: "2"
6 changes: 6 additions & 0 deletions api/v1alpha1/azuresqlfailovergroup_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 (*AzureSqlFailoverGroup) Hub() {}
2 changes: 2 additions & 0 deletions api/v1alpha1/azuresqlfailovergroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type AzureSqlFailoverGroupSpec struct {

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

// AzureSqlFailoverGroup is the Schema for the azuresqlfailovergroups API
// +kubebuilder:printcolumn:name="Provisioned",type="string",JSONPath=".status.provisioned"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message"
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/azuresqlfailovergroup_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 azuresqlfailovergrouplog = logf.Log.WithName("azuresqlfailovergroup-resource")

func (r *AzureSqlFailoverGroup) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
56 changes: 56 additions & 0 deletions api/v1beta1/azuresqlfailovergroup_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1beta1

import (
"github.com/Azure/azure-service-operator/api/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

func (src *AzureSqlFailoverGroup) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1alpha1.AzureSqlFailoverGroup)

// ObjectMeta
dst.ObjectMeta = src.ObjectMeta

// Spec
dst.Spec.ResourceGroup = src.Spec.ResourceGroup
dst.Spec.Location = src.Spec.Location
dst.Spec.Server = src.Spec.Server
dst.Spec.FailoverGracePeriod = src.Spec.FailoverGracePeriod
dst.Spec.FailoverPolicy = src.Spec.FailoverPolicy
dst.Spec.SecondaryServer = src.Spec.SecondaryServer
dst.Spec.SecondaryServerResourceGroup = src.Spec.SecondaryServerResourceGroup
dst.Spec.DatabaseList = src.Spec.DatabaseList
dst.Spec.KeyVaultToStoreSecrets = src.Spec.KeyVaultToStoreSecrets

// Status
dst.Status = src.Status

return nil
}

func (dst *AzureSqlFailoverGroup) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1alpha1.AzureSqlFailoverGroup)

// ObjectMeta
dst.ObjectMeta = src.ObjectMeta

// Spec
dst.Spec.ResourceGroup = src.Spec.ResourceGroup
dst.Spec.Location = src.Spec.Location
dst.Spec.Server = src.Spec.Server
dst.Spec.FailoverGracePeriod = src.Spec.FailoverGracePeriod
dst.Spec.FailoverPolicy = src.Spec.FailoverPolicy
dst.Spec.SecondaryServer = src.Spec.SecondaryServer
dst.Spec.SecondaryServerResourceGroup = src.Spec.SecondaryServerResourceGroup
dst.Spec.DatabaseList = src.Spec.DatabaseList
dst.Spec.KeyVaultToStoreSecrets = src.Spec.KeyVaultToStoreSecrets

// Status
dst.Status = src.Status

return nil

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

package v1beta1

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

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// AzureSqlFailoverGroupSpec defines the desired state of AzureSqlFailoverGroup
type AzureSqlFailoverGroupSpec struct {
// Important: Run "make" to regenerate code after modifying this file
Location string `json:"location"`
ResourceGroup string `json:"resourcegroup,omitempty"`
Server string `json:"server"`
FailoverPolicy v1alpha1.ReadWriteEndpointFailoverPolicy `json:"failoverpolicy"`
FailoverGracePeriod int32 `json:"failovergraceperiod"`
SecondaryServer string `json:"secondaryserver"`
SecondaryServerResourceGroup string `json:"secondaryserverresourcegroup"`
DatabaseList []string `json:"databaselist"`
KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"`
}

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

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

Spec AzureSqlFailoverGroupSpec `json:"spec,omitempty"`
Status v1alpha1.ASOStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&AzureSqlFailoverGroup{}, &AzureSqlFailoverGroupList{})
}

func (s *AzureSqlFailoverGroup) IsSubmitted() bool {
return s.Status.Provisioned || s.Status.Provisioning
}
4 changes: 2 additions & 2 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ patches:
- patches/webhook_in_azuresqldatabases.yaml
- patches/webhook_in_azuresqlfirewallrules.yaml
#- patches/webhook_in_azuresqlactions.yaml
#- patches/webhook_in_azuresqlfailovergroups.yaml
- patches/webhook_in_azuresqlfailovergroups.yaml
#- patches/webhook_in_blobcontainers.yaml
#- patches/webhook_in_appinsights.yaml
#- patches/webhook_in_postgresqlservers.yaml
Expand Down Expand Up @@ -86,7 +86,7 @@ patches:
- patches/cainjection_in_azuresqldatabases.yaml
- patches/cainjection_in_azuresqlfirewallrules.yaml
#- patches/cainjection_in_azuresqlactions.yaml
#- patches/cainjection_in_azuresqlfailovergroups.yaml
- patches/cainjection_in_azuresqlfailovergroups.yaml
#- patches/cainjection_in_blobcontainers.yaml
#- patches/cainjection_in_appinsights.yaml
#- patches/cainjection_in_postgresqlservers.yaml
Expand Down
1 change: 1 addition & 0 deletions config/crd/patches/webhook_in_azuresqlfailovergroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ kind: CustomResourceDefinition
metadata:
name: azuresqlfailovergroups.azure.microsoft.com
spec:
preserveUnknownFields: false
conversion:
strategy: Webhook
webhookClientConfig:
Expand Down
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: docker.io/frodopwns/op3:3
- image: docker.io/frodopwns/op3:4
name: manager
env:
- name: AZURE_CLIENT_ID
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml-e
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: docker.io/frodopwns/op3:2
- image: docker.io/frodopwns/op3:3
name: manager
env:
- name: AZURE_CLIENT_ID
Expand Down
24 changes: 24 additions & 0 deletions config/rbac/azuresqlfailovergroup_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit azuresqlfailovergroups.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: azuresqlfailovergroup-editor-role
rules:
- apiGroups:
- azure.microsoft.com
resources:
- azuresqlfailovergroups
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- azure.microsoft.com
resources:
- azuresqlfailovergroups/status
verbs:
- get
20 changes: 20 additions & 0 deletions config/rbac/azuresqlfailovergroup_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# permissions for end users to view azuresqlfailovergroups.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: azuresqlfailovergroup-viewer-role
rules:
- apiGroups:
- azure.microsoft.com
resources:
- azuresqlfailovergroups
verbs:
- get
- list
- watch
- apiGroups:
- azure.microsoft.com
resources:
- azuresqlfailovergroups/status
verbs:
- get
15 changes: 15 additions & 0 deletions config/samples/azure_v1beta1_azuresqlfailovergroup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: azure.microsoft.com/v1beta1
kind: AzureSqlFailoverGroup
metadata:
name: azuresqlfailovergroup-sample
spec:
location: eastus
resourceGroup: resourcegroup-azure-operators
server: sqlserver-samplepri
failoverpolicy: automatic
failovergraceperiod: 30
secondaryserver: sqlserver-samplesec
secondaryserverresourcegroup: resourcegroup-azure-operators
databaselist:
- "azuresqldatabase-sample"
- "azuresqldatabase-sample2"
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureSqlFirewallRule")
os.Exit(1)
}
if err = (&azurev1alpha1.AzureSqlFailoverGroup{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "AzureSqlFailoverGroup")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

setupLog.Info("starting manager")
Expand Down

0 comments on commit 2ce8469

Please sign in to comment.