diff --git a/controllers/azuresqlserver_controller_finalizer.go b/controllers/azuresqlserver_controller_finalizer.go index d1fabae3029..dc370bcc0f9 100644 --- a/controllers/azuresqlserver_controller_finalizer.go +++ b/controllers/azuresqlserver_controller_finalizer.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + v1 "k8s.io/api/core/v1" azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" helpers "github.com/Azure/azure-service-operator/pkg/helpers" ) @@ -29,8 +30,8 @@ const AzureSQLServerFinalizerName = "azuresqlserver.finalizers.azure.com" func (r *AzureSqlServerReconciler) addFinalizer(instance *azurev1alpha1.AzureSqlServer) error { helpers.AddFinalizer(instance, AzureSQLServerFinalizerName) if updateerr := r.Update(context.Background(), instance); updateerr != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Failed to update finalizer") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Failed to update finalizer") } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", AzureSQLServerFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", AzureSQLServerFinalizerName)) return nil } diff --git a/controllers/consumergroup_controller.go b/controllers/consumergroup_controller.go index 872a8a81063..4c6e26ea21f 100644 --- a/controllers/consumergroup_controller.go +++ b/controllers/consumergroup_controller.go @@ -29,6 +29,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" + v1 "k8s.io/api/core/v1" azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" eventhubsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/eventhubs" @@ -120,7 +121,7 @@ func (r *ConsumerGroupReconciler) createConsumerGroup(instance *azurev1alpha1.Co if err != nil { //log error and kill it, as the parent might not exist in the cluster. It could have been created elsewhere or through the portal directly - r.Recorder.Event(instance, "Warning", "Failed", fmt.Sprintf("Unable to get owner eventhub '%s' of consumer group '%s'", eventhubName, consumergroupName)) + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", fmt.Sprintf("Unable to get owner eventhub '%s' of consumer group '%s'", eventhubName, consumergroupName)) } else { //set owner reference for consumer group if it exists references := []metav1.OwnerReference{ @@ -137,18 +138,18 @@ func (r *ConsumerGroupReconciler) createConsumerGroup(instance *azurev1alpha1.Co err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } _, err = r.ConsumerGroupManager.CreateConsumerGroup(ctx, resourcegroup, namespaceName, eventhubName, azureConsumerGroupName) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create consumer group in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create consumer group in azure") instance.Status.Provisioning = false errUpdate := r.Update(ctx, instance) if errUpdate != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return err } @@ -159,10 +160,10 @@ func (r *ConsumerGroupReconciler) createConsumerGroup(instance *azurev1alpha1.Co err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } - r.Recorder.Event(instance, "Normal", "Updated", consumergroupName+" provisioned") + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", consumergroupName+" provisioned") return nil @@ -179,7 +180,7 @@ func (r *ConsumerGroupReconciler) deleteConsumerGroup(instance *azurev1alpha1.Co var err error _, err = r.ConsumerGroupManager.DeleteConsumerGroup(ctx, resourcegroup, namespaceName, eventhubName, azureConsumerGroupName) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete consumer group in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete consumer group in azure") return err } return nil diff --git a/controllers/consumergroup_controller_finalizer.go b/controllers/consumergroup_controller_finalizer.go index 19f65562ada..f3d5c583909 100644 --- a/controllers/consumergroup_controller_finalizer.go +++ b/controllers/consumergroup_controller_finalizer.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + v1 "k8s.io/api/core/v1" azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" ) @@ -31,7 +32,7 @@ func (r *ConsumerGroupReconciler) addFinalizer(instance *azurev1alpha1.ConsumerG if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", consumerGroupFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", consumerGroupFinalizerName)) return nil } diff --git a/controllers/cosmosdb_controller.go b/controllers/cosmosdb_controller.go index 7bb62932240..b664b17e3ac 100644 --- a/controllers/cosmosdb_controller.go +++ b/controllers/cosmosdb_controller.go @@ -40,6 +40,7 @@ import ( "github.com/Azure/azure-service-operator/pkg/helpers" "github.com/Azure/azure-service-operator/pkg/resourcemanager/cosmosdbs" "k8s.io/client-go/tools/record" + v1 "k8s.io/api/core/v1" ) const cosmosDBFinalizerName = "cosmosdb.finalizers.azure.com" @@ -123,7 +124,7 @@ func (r *CosmosDBReconciler) addFinalizer(instance *azurev1alpha1.CosmosDB) erro if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", cosmosDBFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", cosmosDBFinalizerName)) return nil } @@ -142,16 +143,16 @@ func (r *CosmosDBReconciler) reconcileExternal(instance *azurev1alpha1.CosmosDB) err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } _, err = cosmosdbs.CreateCosmosDB(ctx, groupName, name, location, kind, dbType, nil) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create resource in azure") instance.Status.Provisioning = false errUpdate := r.Update(ctx, instance) if errUpdate != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return errhelp.NewAzureError(err) } @@ -160,9 +161,9 @@ func (r *CosmosDBReconciler) reconcileExternal(instance *azurev1alpha1.CosmosDB) err = r.Update(ctx, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } - r.Recorder.Event(instance, "Normal", "Updated", name+" provisioned") + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", name+" provisioned") return nil } @@ -174,15 +175,15 @@ func (r *CosmosDBReconciler) deleteExternal(instance *azurev1alpha1.CosmosDB) er _, err := cosmosdbs.DeleteCosmosDB(ctx, groupName, name) if err != nil { if errhelp.IsStatusCode204(err) { - r.Recorder.Event(instance, "Warning", "DoesNotExist", "Resource to delete does not exist") + r.Recorder.Event(instance, v1.EventTypeWarning, "DoesNotExist", "Resource to delete does not exist") return nil } - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete resource in azure") return err } - r.Recorder.Event(instance, "Normal", "Deleted", name+" deleted") + r.Recorder.Event(instance, v1.EventTypeNormal, "Deleted", name+" deleted") return nil } diff --git a/controllers/eventhub_controller.go b/controllers/eventhub_controller.go index 1931dfca8cd..21cc65ca4ca 100644 --- a/controllers/eventhub_controller.go +++ b/controllers/eventhub_controller.go @@ -139,7 +139,7 @@ func (r *EventhubReconciler) reapply(instance *azurev1alpha1.Eventhub) error { result, _ := r.EventHubManager.GetHub(ctx, resourcegroup, eventhubNamespace, eventhubName) if result.Response.StatusCode == http.StatusNotFound { r.reconcileExternal(instance) - r.Recorder.Event(instance, "Normal", "Updated", "Resource does not exist in azure, reapplied it") + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", "Resource does not exist in azure, reapplied it") } if result.Response.StatusCode == http.StatusOK { @@ -151,14 +151,14 @@ func (r *EventhubReconciler) reapply(instance *azurev1alpha1.Eventhub) error { if err != nil { err = r.createOrUpdateAccessPolicyEventHub(resourcegroup, eventhubNamespace, eventhubName, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to reapply createAccessPolicyEventHub") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to reapply createAccessPolicyEventHub") return err } } err = r.listAccessKeysAndCreateSecrets(resourcegroup, eventhubNamespace, eventhubName, secretName, instance.Spec.AuthorizationRule.Name, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to reapply listAccessKeysAndCreateSecrets") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to reapply listAccessKeysAndCreateSecrets") return err } } @@ -195,7 +195,7 @@ func (r *EventhubReconciler) reconcileExternal(instance *azurev1alpha1.Eventhub) err = r.Get(ctx, eventhubNamespacedName, &ownerInstance) if err != nil { //log error and kill it, as the parent might not exist in the cluster. It could have been created elsewhere or through the portal directly - r.Recorder.Event(instance, "Warning", "Failed", "Unable to get owner instance of eventhubnamespace") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to get owner instance of eventhubnamespace") } else { //set owner reference for eventhub if it exists references := []metav1.OwnerReference{ @@ -212,32 +212,32 @@ func (r *EventhubReconciler) reconcileExternal(instance *azurev1alpha1.Eventhub) err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } capturePtr := getCaptureDescriptionPtr(captureDescription) _, err = r.EventHubManager.CreateHub(ctx, resourcegroup, eventhubNamespace, eventhubName, messageRetentionInDays, partitionCount, capturePtr) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create resource in azure") instance.Status.Provisioning = false errUpdate := r.Update(ctx, instance) if errUpdate != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return errhelp.NewAzureError(err) } err = r.createOrUpdateAccessPolicyEventHub(resourcegroup, eventhubNamespace, eventhubName, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to createAccessPolicyEventHub") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to createAccessPolicyEventHub") return err } err = r.listAccessKeysAndCreateSecrets(resourcegroup, eventhubNamespace, eventhubName, secretName, instance.Spec.AuthorizationRule.Name, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to listAccessKeysAndCreateSecrets") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to listAccessKeysAndCreateSecrets") return err } @@ -247,7 +247,7 @@ func (r *EventhubReconciler) reconcileExternal(instance *azurev1alpha1.Eventhub) err = r.Update(ctx, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return nil } @@ -292,7 +292,7 @@ func (r *EventhubReconciler) deleteEventhub(instance *azurev1alpha1.Eventhub) er var err error _, err = r.EventHubManager.DeleteHub(ctx, resourcegroup, namespaceName, eventhubName) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete resource in azure") return err } return nil @@ -316,7 +316,7 @@ func (r *EventhubReconciler) createOrUpdateAccessPolicyEventHub(resourcegroup st } _, err = r.EventHubManager.CreateOrUpdateAuthorizationRule(ctx, resourcegroup, eventhubNamespace, eventhubName, authorizationRuleName, parameters) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to createorupdateauthorizationrule") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to createorupdateauthorizationrule") return err } return nil @@ -331,7 +331,7 @@ func (r *EventhubReconciler) listAccessKeysAndCreateSecrets(resourcegroup string result, err = r.EventHubManager.ListKeys(ctx, resourcegroup, eventhubNamespace, eventhubName, authorizationRuleName) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to list keys") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to list keys") } else { //create secrets in the k8s with the listed keys err = r.createEventhubSecrets( @@ -347,7 +347,7 @@ func (r *EventhubReconciler) listAccessKeysAndCreateSecrets(resourcegroup string instance, ) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", fmt.Sprintf("unable to create secret for %s", eventhubName)) + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", fmt.Sprintf("unable to create secret for %s", eventhubName)) return err } } diff --git a/controllers/eventhub_controller_finalizer.go b/controllers/eventhub_controller_finalizer.go index f4be8fd1d6c..fb9b16d4764 100644 --- a/controllers/eventhub_controller_finalizer.go +++ b/controllers/eventhub_controller_finalizer.go @@ -22,6 +22,7 @@ import ( azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" "github.com/Azure/azure-service-operator/pkg/errhelp" + v1 "k8s.io/api/core/v1" ) const eventhubFinalizerName = "eventhub.finalizers.com" @@ -32,7 +33,7 @@ func (r *EventhubReconciler) addFinalizer(instance *azurev1alpha1.Eventhub) erro if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", eventhubFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", eventhubFinalizerName)) return nil } diff --git a/controllers/eventhubnamespace_controller.go b/controllers/eventhubnamespace_controller.go index eec525894c2..aa18e040efb 100644 --- a/controllers/eventhubnamespace_controller.go +++ b/controllers/eventhubnamespace_controller.go @@ -32,6 +32,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" + v1 "k8s.io/api/core/v1" ) // EventhubNamespaceReconciler reconciles a EventhubNamespace object @@ -120,7 +121,7 @@ func (r *EventhubNamespaceReconciler) reconcileExternal(instance *azurev1alpha1. if err != nil { //log error and kill it, as the parent might not exist in the cluster. It could have been created elsewhere or through the portal directly - r.Recorder.Event(instance, "Warning", "Failed", "Unable to get owner instance of resourcegroup") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to get owner instance of resourcegroup") } else { //set owner reference for eventhubnamespace if it exists references := []metav1.OwnerReference{ @@ -137,18 +138,18 @@ func (r *EventhubNamespaceReconciler) reconcileExternal(instance *azurev1alpha1. err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } // create Event Hubs namespace _, err = r.EventHubNamespaceManager.CreateNamespaceAndWait(ctx, resourcegroup, namespaceName, namespaceLocation) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create resource in azure") instance.Status.Provisioning = false errUpdate := r.Update(ctx, instance) if errUpdate != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return errhelp.NewAzureError(err) } @@ -160,10 +161,10 @@ func (r *EventhubNamespaceReconciler) reconcileExternal(instance *azurev1alpha1. err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } - r.Recorder.Event(instance, "Normal", "Updated", namespaceName+" provisioned") + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", namespaceName+" provisioned") return nil @@ -179,7 +180,7 @@ func (r *EventhubNamespaceReconciler) deleteEventhubNamespace(instance *azurev1a var err error _, err = r.EventHubNamespaceManager.DeleteNamespace(ctx, resourcegroup, namespaceName) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete resource in azure") return err } return nil diff --git a/controllers/eventhubnamespace_controller_finalizer.go b/controllers/eventhubnamespace_controller_finalizer.go index 73d25b24647..c5135fb3c37 100644 --- a/controllers/eventhubnamespace_controller_finalizer.go +++ b/controllers/eventhubnamespace_controller_finalizer.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + v1 "k8s.io/api/core/v1" azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" ) @@ -31,7 +32,7 @@ func (r *EventhubNamespaceReconciler) addFinalizer(instance *azurev1alpha1.Event if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", eventhubNamespaceFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", eventhubNamespaceFinalizerName)) return nil } diff --git a/controllers/keyvault_controller.go b/controllers/keyvault_controller.go index 2d10993e0c5..70de2018a48 100644 --- a/controllers/keyvault_controller.go +++ b/controllers/keyvault_controller.go @@ -29,6 +29,7 @@ import ( "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + v1 "k8s.io/api/core/v1" ) const keyVaultFinalizerName = "keyvault.finalizers.azure.com" @@ -94,7 +95,7 @@ func (r *KeyVaultReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return ctrl.Result{}, fmt.Errorf("error reconciling keyvault in azure: %v", err) } - r.Recorder.Event(&instance, "Normal", "Provisioned", "Keyvault "+instance.ObjectMeta.Name+" provisioned ") + r.Recorder.Event(&instance, v1.EventTypeNormal, "Provisioned", "Keyvault "+instance.ObjectMeta.Name+" provisioned ") return ctrl.Result{}, nil } @@ -104,7 +105,7 @@ func (r *KeyVaultReconciler) addFinalizer(instance *azurev1alpha1.KeyVault) erro if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", keyVaultFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", keyVaultFinalizerName)) return nil } @@ -117,21 +118,21 @@ func (r *KeyVaultReconciler) reconcileExternal(instance *azurev1alpha1.KeyVault) var final error if vault, err := r.KeyVaultManager.CreateVault(ctx, groupName, name, location); err != nil { if errhelp.IsAsynchronousOperationNotComplete(err) || errhelp.IsGroupNotFound(err) { - r.Recorder.Event(instance, "Normal", "Provisioning", name+" provisioning") + r.Recorder.Event(instance, v1.EventTypeNormal, "Provisioning", name+" provisioning") return err } instance.Status.ProvisioningState = to.StringPtr("Failed") - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create resource in azure") if err := r.Status().Update(ctx, instance); err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } final = errors.Wrap(err, "failed to update status") } else { instance.Status.ProvisioningState = to.StringPtr("Succeeded") instance.Status.ID = vault.ID if err := r.Status().Update(ctx, instance); err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } final = errors.Wrap(err, "failed to update status") } @@ -145,15 +146,15 @@ func (r *KeyVaultReconciler) deleteExternal(instance *azurev1alpha1.KeyVault) er _, err := r.KeyVaultManager.DeleteVault(ctx, groupName, name) if err != nil { if errhelp.IsStatusCode204(err) { - r.Recorder.Event(instance, "Warning", "DoesNotExist", "Resource to delete does not exist") + r.Recorder.Event(instance, v1.EventTypeWarning, "DoesNotExist", "Resource to delete does not exist") return nil } - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete resouce in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete resouce in azure") return err } - r.Recorder.Event(instance, "Normal", "Deleted", name+" deleted") + r.Recorder.Event(instance, v1.EventTypeNormal, "Deleted", name+" deleted") return nil } diff --git a/controllers/rediscache_controller.go b/controllers/rediscache_controller.go index 877bb128554..b991bcb15e8 100644 --- a/controllers/rediscache_controller.go +++ b/controllers/rediscache_controller.go @@ -40,6 +40,7 @@ import ( "github.com/Azure/azure-service-operator/pkg/helpers" "github.com/Azure/azure-service-operator/pkg/resourcemanager/rediscaches" "k8s.io/client-go/tools/record" + v1 "k8s.io/api/core/v1" ) const redisCacheFinalizerName = "rediscache.finalizers.azure.com" @@ -122,7 +123,7 @@ func (r *RedisCacheReconciler) addFinalizer(instance *azurev1alpha1.RedisCache) if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", redisCacheFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", redisCacheFinalizerName)) return nil } @@ -143,17 +144,17 @@ func (r *RedisCacheReconciler) reconcileExternal(instance *azurev1alpha1.RedisCa err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } _, err = rediscaches.CreateRedisCache(ctx, groupName, name, location, sku, enableNonSSLPort, nil) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create resource in azure") instance.Status.Provisioning = false errUpdate := r.Update(ctx, instance) if errUpdate != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return errhelp.NewAzureError(err) } @@ -163,10 +164,10 @@ func (r *RedisCacheReconciler) reconcileExternal(instance *azurev1alpha1.RedisCa err = r.Update(ctx, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } - r.Recorder.Event(instance, "Normal", "Updated", name+" provisioned") + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", name+" provisioned") return nil } @@ -178,14 +179,14 @@ func (r *RedisCacheReconciler) deleteExternal(instance *azurev1alpha1.RedisCache _, err := rediscaches.DeleteRedisCache(ctx, groupName, name) if err != nil { if errhelp.IsStatusCode204(err) { - r.Recorder.Event(instance, "Warning", "DoesNotExist", "Resource to delete does not exist") + r.Recorder.Event(instance, v1.EventTypeWarning, "DoesNotExist", "Resource to delete does not exist") return nil } - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete resource in azure") return err } - r.Recorder.Event(instance, "Normal", "Deleted", name+" deleted") + r.Recorder.Event(instance, v1.EventTypeNormal, "Deleted", name+" deleted") return nil } diff --git a/controllers/resourcegroup_controller.go b/controllers/resourcegroup_controller.go index 2f4c73854d4..caf351ed60e 100644 --- a/controllers/resourcegroup_controller.go +++ b/controllers/resourcegroup_controller.go @@ -28,6 +28,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" + v1 "k8s.io/api/core/v1" ) // ResourceGroupReconciler reconciles a ResourceGroup object @@ -102,18 +103,18 @@ func (r *ResourceGroupReconciler) reconcileExternal(instance *azurev1alpha1.Reso err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } _, err = r.ResourceGroupManager.CreateGroup(ctx, resourcegroupName, resourcegroupLocation) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create resource in azure") instance.Status.Provisioning = false errUpdate := r.Update(ctx, instance) if errUpdate != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return err } @@ -124,10 +125,10 @@ func (r *ResourceGroupReconciler) reconcileExternal(instance *azurev1alpha1.Reso err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } - r.Recorder.Event(instance, "Normal", "Updated", resourcegroupName+" provisioned") + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", resourcegroupName+" provisioned") return nil @@ -141,7 +142,7 @@ func (r *ResourceGroupReconciler) deleteResourceGroup(instance *azurev1alpha1.Re var err error _, err = r.ResourceGroupManager.DeleteGroup(ctx, resourcegroup) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete resource in azure") return err } return nil diff --git a/controllers/resourcegroup_controller_finalizer.go b/controllers/resourcegroup_controller_finalizer.go index 566e76cd429..5485a9eda6e 100644 --- a/controllers/resourcegroup_controller_finalizer.go +++ b/controllers/resourcegroup_controller_finalizer.go @@ -20,6 +20,7 @@ import ( "context" "fmt" + v1 "k8s.io/api/core/v1" azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" ) @@ -31,7 +32,7 @@ func (r *ResourceGroupReconciler) addFinalizer(instance *azurev1alpha1.ResourceG if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", resourceGroupFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", resourceGroupFinalizerName)) return nil } diff --git a/controllers/storage_controller.go b/controllers/storage_controller.go index 8f3cfa6327b..1c76a9e3b73 100644 --- a/controllers/storage_controller.go +++ b/controllers/storage_controller.go @@ -40,6 +40,7 @@ import ( "github.com/Azure/azure-service-operator/pkg/helpers" "github.com/Azure/azure-service-operator/pkg/resourcemanager/storages" "k8s.io/client-go/tools/record" + v1 "k8s.io/api/core/v1" ) const storageFinalizerName = "storage.finalizers.azure.com" @@ -129,7 +130,7 @@ func (r *StorageReconciler) addFinalizer(instance *azurev1alpha1.Storage) error if err != nil { return fmt.Errorf("failed to update finalizer: %v", err) } - r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", storageFinalizerName)) + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", fmt.Sprintf("finalizer %s added", storageFinalizerName)) return nil } @@ -151,17 +152,17 @@ func (r *StorageReconciler) reconcileExternal(instance *azurev1alpha1.Storage) e err = r.Update(ctx, instance) if err != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } _, err = r.StorageManager.CreateStorage(ctx, groupName, name, location, sku, kind, nil, accessTier, enableHTTPSTrafficOnly) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't create resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't create resource in azure") instance.Status.Provisioning = false errUpdate := r.Update(ctx, instance) if errUpdate != nil { //log error and kill it - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } return errhelp.NewAzureError(err) } @@ -171,10 +172,10 @@ func (r *StorageReconciler) reconcileExternal(instance *azurev1alpha1.Storage) e err = r.Update(ctx, instance) if err != nil { - r.Recorder.Event(instance, "Warning", "Failed", "Unable to update instance") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Unable to update instance") } - r.Recorder.Event(instance, "Normal", "Updated", name+" provisioned") + r.Recorder.Event(instance, v1.EventTypeNormal, "Updated", name+" provisioned") return nil } @@ -186,15 +187,15 @@ func (r *StorageReconciler) deleteExternal(instance *azurev1alpha1.Storage) erro _, err := r.StorageManager.DeleteStorage(ctx, groupName, name) if err != nil { if errhelp.IsStatusCode204(err) { - r.Recorder.Event(instance, "Warning", "DoesNotExist", "Resource to delete does not exist") + r.Recorder.Event(instance, v1.EventTypeWarning, "DoesNotExist", "Resource to delete does not exist") return nil } - r.Recorder.Event(instance, "Warning", "Failed", "Couldn't delete resource in azure") + r.Recorder.Event(instance, v1.EventTypeWarning, "Failed", "Couldn't delete resource in azure") return err } - r.Recorder.Event(instance, "Normal", "Deleted", name+" deleted") + r.Recorder.Event(instance, v1.EventTypeNormal, "Deleted", name+" deleted") return nil }