Skip to content

Commit

Permalink
Merge branch 'master' into eventhub-vnet
Browse files Browse the repository at this point in the history
  • Loading branch information
jananivMS authored Mar 31, 2020
2 parents 399823e + e228fea commit 38ac959
Show file tree
Hide file tree
Showing 32 changed files with 232 additions and 337 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ delete:
kubectl delete -f config/crd/bases
kustomize build config/default | kubectl delete -f -

# Validate copyright headers
validate-copyright-headers:
@./scripts/validate-copyright-headers.sh

# Generate manifests for helm and package them up
helm-chart-manifests: manifests
kustomize build ./config/default -o ./charts/azure-service-operator/templates
Expand All @@ -128,7 +132,7 @@ fmt:
go fmt ./...

# Run go vet against code
vet:
vet:
go vet ./...

# Generate code
Expand Down
8 changes: 5 additions & 3 deletions api/v1alpha1/rediscache_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ type RedisCacheSpec struct {

// RedisCacheProperties the properties of the Redis Cache.
type RedisCacheProperties struct {
Sku RedisCacheSku `json:"sku,omitempty"`

EnableNonSslPort bool `json:"enableNonSslPort,omitempty"`
Sku RedisCacheSku `json:"sku,omitempty"`
EnableNonSslPort bool `json:"enableNonSslPort,omitempty"`
SubnetID string `json:"subnetId,omitempty"`
StaticIP string `json:"staticIp,omitempty"`
Configuration map[string]string `json:"configuration,omitempty"`
}

// RedisCacheSku the SKU of the Redis Cache.
Expand Down
15 changes: 12 additions & 3 deletions config/samples/azure_v1alpha1_rediscache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ metadata:
spec:
location: westus
resourceGroup: resourcegroup-azure-operators
# Use the field below to optionally specify a different keyvault
# to store the primary and secondary key secrets in
# keyVaultToStoreSecrets: asoSecretKeyVault
properties:
# possible values for sku.Name are "Basic", "Premium" or "Standard"
# possible values for sku.family are "C" and "P".
Expand All @@ -17,6 +20,12 @@ spec:
family: C
capacity: 1
enableNonSslPort: true
# Use the field below to optionally specify a different keyvault
# to store the primary and secondary key secrets in
#keyVaultToStoreSecrets: asoSecretKeyVault
## Optional - vnet usage may require a higher tier sku
subnetId: /subscriptions/{SUBID}/resourceGroups/{resourcegroupName}/providers/Microsoft.Network/virtualNetworks/{vnet name}/subnets/{subnet name}
staticIp: 172.22.0.10
# All redis configuration - Few possible keys: rdb-backup-enabled,rdb-storage-connection-string,rdb-backup-frequency,maxmemory-delta,
# maxmemory-policy,notify-keyspace-events,maxmemory-samples,slowlog-log-slower-than,slowlog-max-len,list-max-ziplist-entries,list-max-ziplist-value,
# hash-max-ziplist-entries,hash-max-ziplist-value,set-max-intset-entries,zset-max-ziplist-entries,zset-max-ziplist-value
# configuration:
# key: value

47 changes: 24 additions & 23 deletions controllers/async_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ type AsyncReconciler struct {
}

// Reconcile reconciles the change request
func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (result ctrl.Result, err error) {
func (r *AsyncReconciler) Reconcile(req ctrl.Request, obj runtime.Object) (result ctrl.Result, err error) {
ctx := context.Background()

if err := r.Get(ctx, req.NamespacedName, local); err != nil {
if err := r.Get(ctx, req.NamespacedName, obj); err != nil {
r.Telemetry.LogInfoByInstance("ignorable error", "error during fetch from api server", req.String())
return ctrl.Result{}, client.IgnoreNotFound(err)
}

// get the ASOStatus struct
status, err := r.AzureClient.GetStatus(local)
status, err := r.AzureClient.GetStatus(obj)
if err != nil {
r.Telemetry.LogErrorByInstance("unable to fetch status", err, req.String())
return ctrl.Result{}, err
}

Expand All @@ -61,7 +62,7 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res
status.RequestedAt = &timeNow
}

res, err := meta.Accessor(local)
res, err := meta.Accessor(obj)
if err != nil {
r.Telemetry.LogErrorByInstance("accessor fail", err, req.String())
return ctrl.Result{}, err
Expand All @@ -70,7 +71,7 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res
var keyvaultSecretClient secrets.SecretClient

// Determine if we need to check KeyVault for secrets
KeyVaultName := keyvaultsecretlib.GetKeyVaultName(local)
KeyVaultName := keyvaultsecretlib.GetKeyVaultName(obj)

if len(KeyVaultName) != 0 {
// Instantiate the KeyVault Secret Client
Expand All @@ -83,7 +84,7 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res

// update the status of the resource in kubernetes
status.Message = "Waiting for secretclient keyvault to be available"
return ctrl.Result{RequeueAfter: requeDuration}, r.Status().Update(ctx, local)
return ctrl.Result{RequeueAfter: requeDuration}, r.Status().Update(ctx, obj)
}
}

Expand All @@ -103,48 +104,48 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res
RemoveFinalizer(res, finalizerName)
}
}
r.Recorder.Event(local, corev1.EventTypeNormal, "Skipping", "Skipping reconcile based on provided annotation")
return ctrl.Result{}, r.Update(ctx, local)
r.Recorder.Event(obj, corev1.EventTypeNormal, "Skipping", "Skipping reconcile based on provided annotation")
return ctrl.Result{}, r.Update(ctx, obj)
}

var configOptions []resourcemanager.ConfigOption
if res.GetDeletionTimestamp().IsZero() {
if !HasFinalizer(res, finalizerName) {
AddFinalizer(res, finalizerName)
r.Recorder.Event(local, corev1.EventTypeNormal, "Added", "Object finalizer is added")
return ctrl.Result{}, r.Update(ctx, local)
r.Recorder.Event(obj, corev1.EventTypeNormal, "Added", "Object finalizer is added")
return ctrl.Result{}, r.Update(ctx, obj)
}
} else {
if HasFinalizer(res, finalizerName) {
if len(KeyVaultName) != 0 { //KeyVault was specified in Spec, so use that for secrets
configOptions = append(configOptions, resourcemanager.WithSecretClient(keyvaultSecretClient))
}
found, deleteErr := r.AzureClient.Delete(ctx, local, configOptions...)
found, deleteErr := r.AzureClient.Delete(ctx, obj, configOptions...)
final := multierror.Append(deleteErr)
if err := final.ErrorOrNil(); err != nil {
r.Telemetry.LogErrorByInstance("error deleting object", err, req.String())
r.Recorder.Event(local, corev1.EventTypeWarning, "FailedDelete", fmt.Sprintf("Failed to delete resource: %s", err.Error()))
r.Recorder.Event(obj, corev1.EventTypeWarning, "FailedDelete", fmt.Sprintf("Failed to delete resource: %s", err.Error()))
return ctrl.Result{}, err
}
if !found {
r.Recorder.Event(local, corev1.EventTypeNormal, "Deleted", "Successfully deleted")
r.Recorder.Event(obj, corev1.EventTypeNormal, "Deleted", "Successfully deleted")
RemoveFinalizer(res, finalizerName)
return ctrl.Result{}, r.Update(ctx, local)
return ctrl.Result{}, r.Update(ctx, obj)
}
r.Telemetry.LogInfoByInstance("requeuing", "deletion unfinished", req.String())
return ctrl.Result{RequeueAfter: requeDuration}, r.Status().Update(ctx, local)
return ctrl.Result{RequeueAfter: requeDuration}, r.Status().Update(ctx, obj)
}
return ctrl.Result{}, nil
}

// loop through parents until one is successfully referenced
parents, err := r.AzureClient.GetParents(local)
parents, err := r.AzureClient.GetParents(obj)
for _, p := range parents {
if err := r.Get(ctx, p.Key, p.Target); err == nil {
if pAccessor, err := meta.Accessor(p.Target); err == nil {
if err := controllerutil.SetControllerReference(pAccessor, res, r.Scheme); err == nil {
r.Telemetry.LogInfoByInstance("status", "setting parent reference", req.String())
err := r.Update(ctx, local)
err := r.Update(ctx, obj)
if err != nil {
r.Telemetry.LogErrorByInstance("failed to reference parent", err, req.String())
}
Expand All @@ -160,7 +161,7 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res
configOptions = append(configOptions, resourcemanager.WithSecretClient(keyvaultSecretClient))
}

done, ensureErr := r.AzureClient.Ensure(ctx, local, configOptions...)
done, ensureErr := r.AzureClient.Ensure(ctx, obj, configOptions...)
if ensureErr != nil {
r.Telemetry.LogErrorByInstance("ensure err", ensureErr, req.String())
}
Expand All @@ -172,18 +173,18 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res
}

// update the status of the resource in kubernetes
// Implementations of Ensure() tend to set their outcomes in local.Status
err = r.Status().Update(ctx, local)
// Implementations of Ensure() tend to set their outcomes in obj.Status
err = r.Status().Update(ctx, obj)
if err != nil {
r.Telemetry.LogInfoByInstance("status", "failed updating status", req.String())
}

final := multierror.Append(ensureErr, r.Update(ctx, local))
final := multierror.Append(ensureErr, r.Update(ctx, obj))
err = final.ErrorOrNil()
if err != nil {
r.Recorder.Event(local, corev1.EventTypeWarning, "FailedReconcile", fmt.Sprintf("Failed to reconcile resource: %s", err.Error()))
r.Recorder.Event(obj, corev1.EventTypeWarning, "FailedReconcile", fmt.Sprintf("Failed to reconcile resource: %s", err.Error()))
} else if done {
r.Recorder.Event(local, corev1.EventTypeNormal, "Reconciled", "Successfully reconciled")
r.Recorder.Event(obj, corev1.EventTypeNormal, "Reconciled", "Successfully reconciled")
}

result = ctrl.Result{}
Expand Down
7 changes: 2 additions & 5 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func setup() error {
eventhubNamespaceClient = resourcemanagereventhub.NewEventHubNamespaceClient(ctrl.Log.WithName("controllers").WithName("EventhubNamespace"))

sqlServerManager = resourcemanagersqlserver.NewAzureSqlServerManager(
ctrl.Log.WithName("sqlservermanager").WithName("AzureSqlServer"),
secretClient,
scheme.Scheme,
)
Expand All @@ -176,17 +175,15 @@ func setup() error {
secretClient,
scheme.Scheme,
)
sqlDbManager = resourcemanagersqldb.NewAzureSqlDbManager(ctrl.Log.WithName("sqldbmanager").WithName("AzureSqlDb"))
sqlFirewallRuleManager = resourcemanagersqlfirewallrule.NewAzureSqlFirewallRuleManager(ctrl.Log.WithName("sqlfirewallrulemanager").WithName("AzureSqlFirewallRule"))
sqlDbManager = resourcemanagersqldb.NewAzureSqlDbManager()
sqlFirewallRuleManager = resourcemanagersqlfirewallrule.NewAzureSqlFirewallRuleManager()
sqlVNetRuleManager = resourcemanagersqlvnetrule.NewAzureSqlVNetRuleManager()
sqlFailoverGroupManager = resourcemanagersqlfailovergroup.NewAzureSqlFailoverGroupManager(
ctrl.Log.WithName("sqlfailovergroupmanager").WithName("AzureSqlFailoverGroup"),
secretClient,
scheme.Scheme,
)
consumerGroupClient = resourcemanagereventhub.NewConsumerGroupClient(ctrl.Log.WithName("controllers").WithName("ConsumerGroup"))
sqlUserManager = resourcemanagersqluser.NewAzureSqlUserManager(
ctrl.Log.WithName("sqlusermanager").WithName("AzureSqlUser"),
secretClient,
scheme.Scheme,
)
Expand Down
8 changes: 7 additions & 1 deletion devops/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ steps:
# REQUEUE_AFTER: $(REQUEUE_AFTER)
# workingDirectory: '$(MODULE_PATH)'

- script: |
make validate-copyright-headers
continueOnError: 'false'
displayName: 'Validate Copyright Headers'
workingDirectory: '$(MODULE_PATH)'

- script: |
set -e
GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0
Expand Down Expand Up @@ -136,7 +142,7 @@ steps:
REQUEUE_AFTER: $(REQUEUE_AFTER)
KUBEBUILDER_ASSETS: $(MODULE_PATH)/bin
BUILD_ID: $(Build.BuildId)
workingDirectory: '$(MODULE_PATH)'
workingDirectory: '$(MODULE_PATH)'

- task: AzureCLI@2
displayName: 'Clean up Azure Resources'
Expand Down
16 changes: 6 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,41 @@ go 1.13

require (
cloud.google.com/go v0.37.4 // indirect
github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737 // indirect
github.com/Azure-Samples/azure-sdk-for-go-samples v0.0.0-20190805235326-79e3f3af791c // indirect
github.com/Azure/azure-sdk-for-go v38.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.5.0
github.com/Azure/go-autorest/autorest/adal v0.2.0
github.com/Azure/go-autorest/autorest/azure/auth v0.1.0
github.com/Azure/go-autorest/autorest/date v0.1.0
github.com/Azure/go-autorest/autorest/to v0.2.0
github.com/Azure/go-autorest/autorest/validation v0.1.0
github.com/axw/gocov v1.0.0 // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e
github.com/go-logr/logr v0.1.0
github.com/gobuffalo/envy v1.7.0
github.com/gogo/protobuf v1.2.1 // indirect
github.com/google/go-cmp v0.3.0
github.com/google/gofuzz v1.0.0 // indirect
github.com/google/uuid v1.1.1
github.com/googleapis/gnostic v0.3.0 // indirect
github.com/gophercloud/gophercloud v0.4.0 // indirect
github.com/hashicorp/go-multierror v1.0.0
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/json-iterator/go v1.1.6 // indirect
github.com/marstr/randname v0.0.0-20181206212954-d5b0f288ab8c
github.com/mitchellh/hashstructure v1.0.0
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.7.0
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829
github.com/prometheus/common v0.2.0
github.com/satori/go.uuid v1.2.0
github.com/sethvargo/go-password v0.1.2
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/testify v1.5.1
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 // indirect
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
golang.org/x/sys v0.0.0-20190621203818-d432491b9138 // indirect
golang.org/x/tools v0.0.0-20200130203232-449c356b79e5 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/klog v0.3.3 // indirect
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect
sigs.k8s.io/controller-runtime v0.2.0-beta.4
sigs.k8s.io/controller-tools v0.2.0 // indirect
sigs.k8s.io/kind v0.4.0 // indirect
)
Loading

0 comments on commit 38ac959

Please sign in to comment.