From e091778aaf76937c235f56c800c1ee4f5bc0e7a3 Mon Sep 17 00:00:00 2001 From: MegaByte875 Date: Tue, 5 Mar 2024 17:40:27 +0800 Subject: [PATCH] update local pv provisioner namespace (#466) --- cmd/provisioner/app/provisioner.go | 2 +- ...storage.yaml => local-pv-provisioner.yaml} | 26 ++++++++++++------- pkg/controller/component/storaged_cluster.go | 15 ++++++----- pkg/controller/component/storaged_failover.go | 13 +++++----- 4 files changed, 32 insertions(+), 24 deletions(-) rename config/samples/{local-pv-storage.yaml => local-pv-provisioner.yaml} (85%) diff --git a/cmd/provisioner/app/provisioner.go b/cmd/provisioner/app/provisioner.go index 06c382a5..b63cddcd 100644 --- a/cmd/provisioner/app/provisioner.go +++ b/cmd/provisioner/app/provisioner.go @@ -36,7 +36,7 @@ import ( ) const ( - defaultProvisionerNamespace = "local-pv-storage" + defaultProvisionerNamespace = "local-pv-provisioner" ) // NewProvisionerCommand creates a *cobra.Command object with default parameters diff --git a/config/samples/local-pv-storage.yaml b/config/samples/local-pv-provisioner.yaml similarity index 85% rename from config/samples/local-pv-storage.yaml rename to config/samples/local-pv-provisioner.yaml index 29538f59..1fa32138 100644 --- a/config/samples/local-pv-storage.yaml +++ b/config/samples/local-pv-provisioner.yaml @@ -1,21 +1,21 @@ apiVersion: v1 kind: Namespace metadata: - name: local-pv-storage + name: local-pv-provisioner --- apiVersion: v1 kind: ServiceAccount metadata: name: local-pv-provisioner-sa - namespace: local-pv-storage + namespace: local-pv-provisioner --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: local-pv-provisioner-role - namespace: local-pv-storage + namespace: local-pv-provisioner rules: - apiGroups: [""] resources: ["pods"] @@ -28,14 +28,20 @@ metadata: name: local-pv-provisioner-role rules: - apiGroups: [""] - resources: ["nodes", "persistentvolumeclaims", "configmaps", "pods", "pods/log"] + resources: ["nodes", "configmaps", "pods", "pods/log"] verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["get", "list", "update", "watch"] - apiGroups: [""] resources: ["persistentvolumes"] verbs: ["get", "list", "watch", "create", "patch", "update", "delete"] - apiGroups: [""] resources: ["events"] - verbs: ["create", "patch"] + verbs: ["watch"] + - apiGroups: ["", "events.k8s.io"] + resources: ["events"] + verbs: ["create", "update", "patch"] - apiGroups: ["storage.k8s.io"] resources: ["storageclasses"] verbs: ["get", "list", "watch"] @@ -45,7 +51,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: local-pv-provisioner-bind - namespace: local-pv-storage + namespace: local-pv-provisioner roleRef: apiGroup: rbac.authorization.k8s.io kind: Role @@ -53,7 +59,7 @@ roleRef: subjects: - kind: ServiceAccount name: local-pv-provisioner-sa - namespace: local-pv-storage + namespace: local-pv-provisioner --- apiVersion: rbac.authorization.k8s.io/v1 @@ -67,14 +73,14 @@ roleRef: subjects: - kind: ServiceAccount name: local-pv-provisioner-sa - namespace: local-pv-storage + namespace: local-pv-provisioner --- apiVersion: apps/v1 kind: Deployment metadata: name: local-pv-provisioner - namespace: local-pv-storage + namespace: local-pv-provisioner spec: replicas: 1 selector: @@ -119,7 +125,7 @@ kind: ConfigMap apiVersion: v1 metadata: name: local-pv-config - namespace: local-pv-storage + namespace: local-pv-provisioner data: setup: |- #!/bin/bash diff --git a/pkg/controller/component/storaged_cluster.go b/pkg/controller/component/storaged_cluster.go index f7bc35cf..708aed67 100644 --- a/pkg/controller/component/storaged_cluster.go +++ b/pkg/controller/component/storaged_cluster.go @@ -309,6 +309,10 @@ func (c *storagedCluster) syncNebulaClusterStatus( nc.Status.Storaged.Phase = v1alpha1.UpdatePhase } + if !nc.IsAutoFailoverEnabled() { + return syncComponentStatus(nc.StoragedComponent(), &nc.Status.Storaged.ComponentStatus, oldWorkload) + } + options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true)) if err != nil { return err @@ -322,10 +326,6 @@ func (c *storagedCluster) syncNebulaClusterStatus( _ = metaClient.Disconnect() }() - if !nc.IsAutoFailoverEnabled() { - return syncComponentStatus(nc.StoragedComponent(), &nc.Status.Storaged.ComponentStatus, oldWorkload) - } - hostItems, err := metaClient.ListHosts(meta.ListHostType_STORAGE) if err != nil { return err @@ -338,8 +338,8 @@ func (c *storagedCluster) syncNebulaClusterStatus( if nc.Status.Storaged.FailureHosts == nil { nc.Status.Storaged.FailureHosts = make(map[string]v1alpha1.StoragedFailureHost) } - fh, exits := nc.Status.Storaged.FailureHosts[podName] - if exits { + fh, exists := nc.Status.Storaged.FailureHosts[podName] + if exists { deadline := fh.CreationTime.Add(nc.Spec.FailoverPeriod.Duration) if time.Now().After(deadline) { if fh.ConfirmationTime.IsZero() { @@ -533,9 +533,10 @@ func (c *storagedCluster) updateZoneMappings(nc *v1alpha1.NebulaCluster, newRepl return nil } +// TODO support partially recovery func (c *storagedCluster) shouldRecover(nc *v1alpha1.NebulaCluster) (bool, error) { if nc.Status.Storaged.FailureHosts == nil { - return false, nil + return true, nil } fhSet := sets.New[string]() diff --git a/pkg/controller/component/storaged_failover.go b/pkg/controller/component/storaged_failover.go index 16a3e799..c25d629e 100644 --- a/pkg/controller/component/storaged_failover.go +++ b/pkg/controller/component/storaged_failover.go @@ -45,7 +45,7 @@ const ( ) var ( - taints = []*corev1.Taint{ + nodeTaints = []*corev1.Taint{ { Key: corev1.TaintNodeUnreachable, Effect: corev1.TaintEffectNoExecute, @@ -74,8 +74,8 @@ func (s *storagedFailover) Failover(nc *v1alpha1.NebulaCluster) error { if err != nil { return err } - if len(readyPods) == len(nc.Status.Storaged.FailureHosts) { - return nil + if len(readyPods) > 0 { + return utilerrors.ReconcileErrorf("storaged pods [%v] are ready after restarted", readyPods) } if err := s.deleteFailureHost(nc); err != nil { return err @@ -96,6 +96,7 @@ func (s *storagedFailover) Failover(nc *v1alpha1.NebulaCluster) error { func (s *storagedFailover) Recovery(nc *v1alpha1.NebulaCluster) error { nc.Status.Storaged.FailureHosts = nil + nc.Status.Storaged.BalancedAfterFailover = nil klog.Infof("clearing storaged cluster [%s/%s] failure hosts", nc.GetNamespace(), nc.GetName()) return nil } @@ -378,9 +379,9 @@ func getPodPvcs(clientSet kube.ClientSet, nc *v1alpha1.NebulaCluster, podName st } func isNodeDown(node *corev1.Node) bool { - for i := range taints { - if taintExists(node.Spec.Taints, taints[i]) { - klog.Infof("node %s found taint %s", node.Name, taints[i].Key) + for i := range nodeTaints { + if taintExists(node.Spec.Taints, nodeTaints[i]) { + klog.Infof("node %s found taint %s", node.Name, nodeTaints[i].Key) return true } }