diff --git a/api/go.mod b/api/go.mod index b79f78be..286317f2 100644 --- a/api/go.mod +++ b/api/go.mod @@ -79,3 +79,7 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fao89/lib-common/modules/common v0.0.0-20240411232537-ab9c8a7381a6 + +replace github.com/openstack-k8s-operators/lib-common/modules/storage => github.com/fao89/lib-common/modules/storage v0.0.0-20240411232537-ab9c8a7381a6 diff --git a/api/go.sum b/api/go.sum index 2d75efd3..eeeb0931 100644 --- a/api/go.sum +++ b/api/go.sum @@ -15,6 +15,10 @@ github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRr github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= +github.com/fao89/lib-common/modules/common v0.0.0-20240411232537-ab9c8a7381a6 h1:aCeNn0W/hn2XqZMxtoBX8qqSTM71n7hkEef+Eu7tYX0= +github.com/fao89/lib-common/modules/common v0.0.0-20240411232537-ab9c8a7381a6/go.mod h1:gqByVGUdKQB/NkhKV4eD+8NWYkHq961nC96rTCB3ywE= +github.com/fao89/lib-common/modules/storage v0.0.0-20240411232537-ab9c8a7381a6 h1:laZkLXtEWIbGPU6T/AShYQFdzRFvirn2qOISD59Tbww= +github.com/fao89/lib-common/modules/storage v0.0.0-20240411232537-ab9c8a7381a6/go.mod h1:/ieOXgiSRmc2LpZ9kCnvtXagh/QM88prKpisVNLwrjg= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= @@ -94,10 +98,6 @@ github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8 github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk= github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg= -github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240408095526-357d8fffa034 h1:HLI/aUA7KnBK5oLPIWXMasz7zqjal4GhNn1P/fdLI20= -github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240408095526-357d8fffa034/go.mod h1:gqByVGUdKQB/NkhKV4eD+8NWYkHq961nC96rTCB3ywE= -github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240408095526-357d8fffa034 h1:LDWJWy545zW7KsZ2d2d+J5mJJK5eX/pL7mnSqn63PH4= -github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240408095526-357d8fffa034/go.mod h1:/ieOXgiSRmc2LpZ9kCnvtXagh/QM88prKpisVNLwrjg= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/controllers/openstack_ansibleee_controller.go b/controllers/openstack_ansibleee_controller.go index 916cc399..b6bcf63d 100644 --- a/controllers/openstack_ansibleee_controller.go +++ b/controllers/openstack_ansibleee_controller.go @@ -39,6 +39,7 @@ import ( util "github.com/openstack-k8s-operators/lib-common/modules/common/util" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" @@ -55,8 +56,9 @@ const ( // OpenStackAnsibleEEReconciler reconciles a OpenStackAnsibleEE object type OpenStackAnsibleEEReconciler struct { client.Client - Kclient kubernetes.Interface - Scheme *runtime.Scheme + Kclient kubernetes.Interface + Scheme *runtime.Scheme + Recorder record.EventRecorder } // GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields @@ -95,6 +97,7 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R r.Kclient, r.Scheme, Log, + r.Recorder, ) if err != nil { @@ -160,10 +163,11 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R netAtt)) return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) } + r.Recorder.Event(instance, corev1.EventTypeWarning, "NetworkAttachmentsError", err.Error()) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.ErrorReason, - condition.SeverityWarning, + condition.SeverityError, condition.NetworkAttachmentsReadyErrorMessage, err.Error())) return ctrl.Result{}, err @@ -217,10 +221,11 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R } if err != nil { + r.Recorder.Event(instance, corev1.EventTypeWarning, "AnsibleExecutionJobError", err.Error()) instance.Status.Conditions.Set(condition.FalseCondition( ansibleeev1.AnsibleExecutionJobReadyCondition, condition.ErrorReason, - condition.SeverityWarning, + condition.SeverityError, ansibleeev1.AnsibleExecutionJobErrorMessage, err.Error())) instance.Status.JobStatus = ansibleeev1.JobStatusFailed @@ -232,6 +237,7 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R Log.Info(fmt.Sprintf("AnsibleEE CR '%s' - Job %s hash added - %s", instance.Name, jobDef.Name, instance.Status.Hash[ansibleeeJobType])) } + r.Recorder.Event(instance, corev1.EventTypeNormal, "AnsibleExecutionJobReady", ansibleeev1.AnsibleExecutionJobReadyMessage) instance.Status.Conditions.MarkTrue(ansibleeev1.AnsibleExecutionJobReadyCondition, ansibleeev1.AnsibleExecutionJobReadyMessage) instance.Status.JobStatus = ansibleeev1.JobStatusSucceeded diff --git a/go.mod b/go.mod index f19e2b2f..fe17e483 100644 --- a/go.mod +++ b/go.mod @@ -84,3 +84,7 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fao89/lib-common/modules/common v0.0.0-20240411232537-ab9c8a7381a6 + +replace github.com/openstack-k8s-operators/lib-common/modules/storage => github.com/fao89/lib-common/modules/storage v0.0.0-20240411232537-ab9c8a7381a6 diff --git a/go.sum b/go.sum index 2cb430f7..8e63c591 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,10 @@ github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRr github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= +github.com/fao89/lib-common/modules/common v0.0.0-20240411232537-ab9c8a7381a6 h1:aCeNn0W/hn2XqZMxtoBX8qqSTM71n7hkEef+Eu7tYX0= +github.com/fao89/lib-common/modules/common v0.0.0-20240411232537-ab9c8a7381a6/go.mod h1:gqByVGUdKQB/NkhKV4eD+8NWYkHq961nC96rTCB3ywE= +github.com/fao89/lib-common/modules/storage v0.0.0-20240411232537-ab9c8a7381a6 h1:laZkLXtEWIbGPU6T/AShYQFdzRFvirn2qOISD59Tbww= +github.com/fao89/lib-common/modules/storage v0.0.0-20240411232537-ab9c8a7381a6/go.mod h1:/ieOXgiSRmc2LpZ9kCnvtXagh/QM88prKpisVNLwrjg= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= @@ -98,10 +102,6 @@ github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk= github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg= github.com/openshift/api v3.9.0+incompatible h1:fJ/KsefYuZAjmrr3+5U9yZIZbTOpVkDDLDLFresAeYs= github.com/openshift/api v3.9.0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY= -github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240408095526-357d8fffa034 h1:HLI/aUA7KnBK5oLPIWXMasz7zqjal4GhNn1P/fdLI20= -github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240408095526-357d8fffa034/go.mod h1:gqByVGUdKQB/NkhKV4eD+8NWYkHq961nC96rTCB3ywE= -github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240408095526-357d8fffa034 h1:LDWJWy545zW7KsZ2d2d+J5mJJK5eX/pL7mnSqn63PH4= -github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240408095526-357d8fffa034/go.mod h1:/ieOXgiSRmc2LpZ9kCnvtXagh/QM88prKpisVNLwrjg= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/main.go b/main.go index 95888ed5..aaaca303 100644 --- a/main.go +++ b/main.go @@ -121,9 +121,10 @@ func main() { } if err = (&controllers.OpenStackAnsibleEEReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - Kclient: kclient, + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + Kclient: kclient, + Recorder: mgr.GetEventRecorderFor("OpenStackAnsibleEE"), }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "OpenStackAnsibleEE") os.Exit(1)