Skip to content

Commit

Permalink
update local pv provisioner namespace (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaByte875 authored Mar 5, 2024
1 parent 2519e3a commit e091778
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cmd/provisioner/app/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

const (
defaultProvisionerNamespace = "local-pv-storage"
defaultProvisionerNamespace = "local-pv-provisioner"
)

// NewProvisionerCommand creates a *cobra.Command object with default parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"]
Expand All @@ -45,15 +51,15 @@ 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
name: local-pv-provisioner-role
subjects:
- kind: ServiceAccount
name: local-pv-provisioner-sa
namespace: local-pv-storage
namespace: local-pv-provisioner

---
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions pkg/controller/component/storaged_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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]()
Expand Down
13 changes: 7 additions & 6 deletions pkg/controller/component/storaged_failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
)

var (
taints = []*corev1.Taint{
nodeTaints = []*corev1.Taint{
{
Key: corev1.TaintNodeUnreachable,
Effect: corev1.TaintEffectNoExecute,
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit e091778

Please sign in to comment.