From 86737a2d5d191656c89d8901c8c0fea573122d58 Mon Sep 17 00:00:00 2001 From: whg517 Date: Thu, 16 Nov 2023 18:57:54 +0800 Subject: [PATCH] feat: add bundle metadata and fix secret --- Makefile | 2 +- ...astore-operator.clusterserviceversion.yaml | 2 + internal/controller/handle.go | 4 +- .../controller/hivemetastore_controller.go | 63 +++++++++---------- 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index e530844..45f7fb9 100644 --- a/Makefile +++ b/Makefile @@ -185,7 +185,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions -KUSTOMIZE_VERSION ?= v5.1.1 +KUSTOMIZE_VERSION ?= v5.2.1 CONTROLLER_TOOLS_VERSION ?= v0.13.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" diff --git a/config/manifests/bases/hive-metastore-operator.clusterserviceversion.yaml b/config/manifests/bases/hive-metastore-operator.clusterserviceversion.yaml index 744281e..7a58be1 100644 --- a/config/manifests/bases/hive-metastore-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/hive-metastore-operator.clusterserviceversion.yaml @@ -4,6 +4,8 @@ metadata: annotations: alm-examples: '[]' capabilities: Basic Install + categories: 'Storage, Compute' + datasuit: 'Develop, Analysis, Governance' name: hive-metastore-operator.v0.0.0 namespace: placeholder spec: diff --git a/internal/controller/handle.go b/internal/controller/handle.go index 9e53b1a..d612ed4 100644 --- a/internal/controller/handle.go +++ b/internal/controller/handle.go @@ -175,7 +175,7 @@ func makeSecret(ctx context.Context, instance *stackv1alpha1.HiveMetastore, sche data["POSTGRES_DB"] = []byte(instance.Spec.PostgresSecret.DataBase) secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: instance.GetNameWithSuffix("-secret"), + Name: instance.GetNameWithSuffix("secret"), Namespace: instance.Namespace, Labels: labels, }, @@ -198,7 +198,5 @@ func (r *HiveMetastoreReconciler) reconcileSecret(ctx context.Context, instance return err } } - // Create or update the secret - return nil } diff --git a/internal/controller/hivemetastore_controller.go b/internal/controller/hivemetastore_controller.go index 58ca831..6cbc514 100644 --- a/internal/controller/hivemetastore_controller.go +++ b/internal/controller/hivemetastore_controller.go @@ -20,6 +20,8 @@ import ( "context" "github.com/go-logr/logr" stackv1alpha1 "github.com/zncdata-labs/hive-metastore-operator/api/v1alpha1" + apimeta "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" @@ -67,18 +69,23 @@ func (r *HiveMetastoreReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, nil } - //// Get the status condition, if it exists and its generation is not the - ////same as the HiveMetastore's generation, reset the status conditions - //readCondition := apimeta.FindStatusCondition(hiveMetastore.Status.Conditions, stackv1alpha1.ConditionTypeProgressing) - //if readCondition == nil || readCondition.ObservedGeneration != hiveMetastore.GetGeneration() { - // hiveMetastore.InitStatusConditions() - // - // if err := r.UpdateStatus(ctx, hiveMetastore); err != nil { - // return ctrl.Result{}, err - // } - //} - // - //r.Log.Info("HiveMetastore found", "Name", hiveMetastore.Name) + // Get the status condition, if it exists and its generation is not the + //same as the HiveMetastore's generation, reset the status conditions + readCondition := apimeta.FindStatusCondition(hiveMetastore.Status.Conditions, stackv1alpha1.ConditionTypeProgressing) + if readCondition == nil || readCondition.ObservedGeneration != hiveMetastore.GetGeneration() { + hiveMetastore.InitStatusConditions() + + if err := r.UpdateStatus(ctx, hiveMetastore); err != nil { + return ctrl.Result{}, err + } + } + + r.Log.Info("HiveMetastore found", "Name", hiveMetastore.Name) + + if err := r.reconcileSecret(ctx, hiveMetastore); err != nil { + r.Log.Error(err, "unable to reconcile Secret") + return ctrl.Result{}, err + } if err := r.reconcileDeployment(ctx, hiveMetastore); err != nil { r.Log.Error(err, "unable to reconcile Deployment") @@ -90,23 +97,18 @@ func (r *HiveMetastoreReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, err } - if err := r.reconcileSecret(ctx, hiveMetastore); err != nil { - r.Log.Error(err, "unable to reconcile Secret") + hiveMetastore.SetStatusCondition(metav1.Condition{ + Type: stackv1alpha1.ConditionTypeAvailable, + Status: metav1.ConditionTrue, + Reason: stackv1alpha1.ConditionReasonRunning, + Message: "HiveMetastore is running", + ObservedGeneration: hiveMetastore.GetGeneration(), + }) + + if err := r.UpdateStatus(ctx, hiveMetastore); err != nil { return ctrl.Result{}, err } - //hiveMetastore.SetStatusCondition(metav1.Condition{ - // Type: stackv1alpha1.ConditionTypeAvailable, - // Status: metav1.ConditionTrue, - // Reason: stackv1alpha1.ConditionReasonRunning, - // Message: "HiveMetastore is running", - // ObservedGeneration: hiveMetastore.GetGeneration(), - //}) - - //if err := r.UpdateStatus(ctx, hiveMetastore); err != nil { - // return ctrl.Result{}, err - //} - r.Log.Info("Successfully reconciled hiveMetastore") return ctrl.Result{}, nil } @@ -122,15 +124,6 @@ func (r *HiveMetastoreReconciler) UpdateStatus(ctx context.Context, instance *st return retryErr } - //if err := r.Get(ctx, key, latest); err != nil { - // r.Log.Error(err, "Failed to get latest object") - // return err - //} - - //if err := r.Status().Patch(ctx, instance, client.MergeFrom(instance)); err != nil { - // r.Log.Error(err, "Failed to patch object status") - // return err - //} r.Log.V(1).Info("Successfully patched object status") return nil }