-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into issue#946#pgreSqlReplica
- Loading branch information
Showing
16 changed files
with
600 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// MySQLVNetRuleSpec defines the desired state of MySQLVNetRule | ||
type MySQLVNetRuleSpec struct { | ||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
ResourceGroup string `json:"resourceGroup"` | ||
Server string `json:"server"` | ||
VNetResourceGroup string `json:"vNetResourceGroup"` | ||
VNetName string `json:"vNetName"` | ||
SubnetName string `json:"subnetName"` | ||
IgnoreMissingServiceEndpoint bool `json:"ignoreMissingServiceEndpoint,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// MySQLVNetRule is the Schema for the mysqlvnetrules API | ||
type MySQLVNetRule struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec MySQLVNetRuleSpec `json:"spec,omitempty"` | ||
Status ASOStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// MySQLVNetRuleList contains a list of MySQLVNetRule | ||
type MySQLVNetRuleList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []MySQLVNetRule `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&MySQLVNetRule{}, &MySQLVNetRuleList{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# The following patch adds a directive for certmanager to inject CA into the CRD | ||
# CRD conversion requires k8s 1.13 or later. | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) | ||
name: mysqlvnetrules.azure.microsoft.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# The following patch enables conversion webhook for CRD | ||
# CRD conversion requires k8s 1.13 or later. | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: mysqlvnetrules.azure.microsoft.com | ||
spec: | ||
conversion: | ||
strategy: Webhook | ||
webhookClientConfig: | ||
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, | ||
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) | ||
caBundle: Cg== | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
path: /convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: azure.microsoft.com/v1alpha1 | ||
kind: MySQLVNetRule | ||
metadata: | ||
name: mysqlvnetrule-sample | ||
spec: | ||
resourceGroup: resourcegroup-azure-operators | ||
server: mysqlserver-sample | ||
vNetResourceGroup: resourcegroup-vnet | ||
vNetName: virtualnetwork-sample | ||
subnetName: test1 | ||
ignoreMissingServiceEndpoint: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package controllers | ||
|
||
import ( | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" | ||
) | ||
|
||
// MySQLVNetRuleReconciler reconciles a MySQLVNetRule object | ||
type MySQLVNetRuleReconciler struct { | ||
Reconciler *AsyncReconciler | ||
} | ||
|
||
// +kubebuilder:rbac:groups=azure.microsoft.com,resources=mysqlvnetrules,verbs=get;list;watch;create;update;patch;delete | ||
// +kubebuilder:rbac:groups=azure.microsoft.com,resources=mysqlvnetrules/status,verbs=get;update;patch | ||
|
||
func (r *MySQLVNetRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { | ||
return r.Reconciler.Reconcile(req, &azurev1alpha1.MySQLVNetRule{}) | ||
} | ||
|
||
func (r *MySQLVNetRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&azurev1alpha1.MySQLVNetRule{}). | ||
Complete(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
// +build all mysql | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/Azure/azure-service-operator/pkg/errhelp" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func TestMySqlVNetRuleControllerNoResourceGroup(t *testing.T) { | ||
t.Parallel() | ||
defer PanicRecover(t) | ||
ctx := context.Background() | ||
assert := assert.New(t) | ||
|
||
// Add any setup steps that needs to be executed before each test | ||
mySqlServerName := GenerateTestResourceNameWithRandom("mysqlvnetrule-test-srv", 10) | ||
mySqlVNetRuleName := GenerateTestResourceNameWithRandom("vnetrule-dev", 10) | ||
|
||
// Create the SqlVnetRule object and expect the Reconcile to be created | ||
mySqlVNetRuleInstance := &azurev1alpha1.MySQLVNetRule{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: mySqlVNetRuleName, | ||
Namespace: "default", | ||
}, | ||
Spec: azurev1alpha1.MySQLVNetRuleSpec{ | ||
ResourceGroup: GenerateTestResourceNameWithRandom("rg-fake-srv", 10), | ||
Server: mySqlServerName, | ||
VNetResourceGroup: "vnet-rg", | ||
VNetName: "test-vnet", | ||
SubnetName: "subnet1", | ||
IgnoreMissingServiceEndpoint: true, | ||
}, | ||
} | ||
|
||
err := tc.k8sClient.Create(ctx, mySqlVNetRuleInstance) | ||
assert.Equal(nil, err, "create mysqlvnetrule in k8s") | ||
|
||
mySqlVNETRuleNamespacedName := types.NamespacedName{Name: mySqlVNetRuleName, Namespace: "default"} | ||
|
||
assert.Eventually(func() bool { | ||
err = tc.k8sClient.Get(ctx, mySqlVNETRuleNamespacedName, mySqlVNetRuleInstance) | ||
if err == nil { | ||
return HasFinalizer(mySqlVNetRuleInstance, finalizerName) | ||
} else { | ||
return false | ||
} | ||
}, tc.timeout, tc.retry, "wait for mysqlvnetrule to have finalizer") | ||
|
||
assert.Eventually(func() bool { | ||
err = tc.k8sClient.Get(ctx, mySqlVNETRuleNamespacedName, mySqlVNetRuleInstance) | ||
if err == nil { | ||
return strings.Contains(mySqlVNetRuleInstance.Status.Message, errhelp.ResourceGroupNotFoundErrorCode) | ||
} else { | ||
return false | ||
} | ||
}, tc.timeout, tc.retry, "wait for mysqlvnetrule to have rg not found error") | ||
|
||
err = tc.k8sClient.Delete(ctx, mySqlVNetRuleInstance) | ||
assert.Equal(nil, err, "delete mysqlvnetrule in k8s") | ||
|
||
assert.Eventually(func() bool { | ||
err = tc.k8sClient.Get(ctx, mySqlVNETRuleNamespacedName, mySqlVNetRuleInstance) | ||
return apierrors.IsNotFound(err) | ||
}, tc.timeout, tc.retry, "wait for mysqlvnetrule to be gone from k8s") | ||
} | ||
|
||
func RunMySqlVNetRuleHappyPath(t *testing.T, mySqlServerName string, rgLocation string) { | ||
defer PanicRecover(t) | ||
ctx := context.Background() | ||
|
||
mySqlVNetRuleName := GenerateTestResourceNameWithRandom("vnet-rule", 10) | ||
VNetName := GenerateTestResourceNameWithRandom("vnet", 10) | ||
subnetName := "subnet-test" | ||
VNetSubNetInstance := azurev1alpha1.VNetSubnets{ | ||
SubnetName: subnetName, | ||
SubnetAddressPrefix: "110.1.0.0/16", | ||
} | ||
|
||
// Create a VNET | ||
VNetInstance := &azurev1alpha1.VirtualNetwork{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: VNetName, | ||
Namespace: "default", | ||
}, | ||
Spec: azurev1alpha1.VirtualNetworkSpec{ | ||
Location: rgLocation, | ||
ResourceGroup: tc.resourceGroupName, | ||
AddressSpace: "110.0.0.0/8", | ||
Subnets: []azurev1alpha1.VNetSubnets{VNetSubNetInstance}, | ||
}, | ||
} | ||
|
||
EnsureInstance(ctx, t, tc, VNetInstance) | ||
|
||
// Create a VNet Rule | ||
|
||
mySqlVNetRuleInstance := &azurev1alpha1.MySQLVNetRule{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: mySqlVNetRuleName, | ||
Namespace: "default", | ||
}, | ||
Spec: azurev1alpha1.MySQLVNetRuleSpec{ | ||
ResourceGroup: tc.resourceGroupName, | ||
Server: mySqlServerName, | ||
VNetResourceGroup: tc.resourceGroupName, | ||
VNetName: VNetName, | ||
SubnetName: subnetName, | ||
IgnoreMissingServiceEndpoint: true, | ||
}, | ||
} | ||
|
||
// Create VNet Rule and ensure it was created | ||
EnsureInstance(ctx, t, tc, mySqlVNetRuleInstance) | ||
|
||
// Delete a VNet Rule and ensure it was deleted | ||
EnsureDelete(ctx, t, tc, mySqlVNetRuleInstance) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.