Skip to content

Commit

Permalink
support component topology constraints (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaByte875 authored Nov 17, 2023
1 parent 17ace23 commit 832f1f2
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apis/apps/v1alpha1/nebulacluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func generateStatefulSet(c NebulaClusterComponent, cm *corev1.ConfigMap) (*appsv
ServiceAccountName: NebulaServiceAccountName,
}

podSpec.TopologySpreadConstraints = getTopologySpreadConstraints(nc.Spec.TopologySpreadConstraints, componentLabel)
podSpec.TopologySpreadConstraints = c.ComponentSpec().TopologySpreadConstraints(componentLabel)

volumeClaim, err := c.GenerateVolumeClaim()
if err != nil {
Expand Down
30 changes: 22 additions & 8 deletions apis/apps/v1alpha1/nebulacluster_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ComponentAccessor interface {
NodeSelector() map[string]string
Affinity() *corev1.Affinity
Tolerations() []corev1.Toleration
TopologySpreadConstraints(labels map[string]string) []corev1.TopologySpreadConstraint
SecurityContext() *corev1.SecurityContext
InitContainers() []corev1.Container
SidecarContainers() []corev1.Container
Expand All @@ -50,10 +51,11 @@ var _ ComponentAccessor = &componentAccessor{}

// +k8s:deepcopy-gen=false
type componentAccessor struct {
nodeSelector map[string]string
affinity *corev1.Affinity
tolerations []corev1.Toleration
componentSpec *ComponentSpec
nodeSelector map[string]string
affinity *corev1.Affinity
tolerations []corev1.Toleration
topologySpreadConstraints []TopologySpreadConstraint
componentSpec *ComponentSpec
}

func (a *componentAccessor) Replicas() int32 {
Expand Down Expand Up @@ -125,6 +127,17 @@ func (a *componentAccessor) Tolerations() []corev1.Toleration {
return a.componentSpec.Tolerations
}

func (a *componentAccessor) TopologySpreadConstraints(labels map[string]string) []corev1.TopologySpreadConstraint {
tscs := a.topologySpreadConstraints
if a.componentSpec != nil && len(a.componentSpec.TopologySpreadConstraints) > 0 {
tscs = a.componentSpec.TopologySpreadConstraints
}
if len(tscs) == 0 {
return nil
}
return getTopologySpreadConstraints(tscs, labels)
}

func (a *componentAccessor) SecurityContext() *corev1.SecurityContext {
if a.componentSpec == nil {
return nil
Expand Down Expand Up @@ -301,9 +314,10 @@ func (c *baseComponent) GenerateOwnerReferences() []metav1.OwnerReference {

func buildComponentAccessor(nc *NebulaCluster, componentSpec *ComponentSpec) ComponentAccessor {
return &componentAccessor{
nodeSelector: nc.Spec.NodeSelector,
affinity: nc.Spec.Affinity,
tolerations: nc.Spec.Tolerations,
componentSpec: componentSpec,
nodeSelector: nc.Spec.NodeSelector,
affinity: nc.Spec.Affinity,
tolerations: nc.Spec.Tolerations,
topologySpreadConstraints: nc.Spec.TopologySpreadConstraints,
componentSpec: componentSpec,
}
}
3 changes: 3 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ type ComponentSpec struct {
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// +optional
TopologySpreadConstraints []TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`

// +optional
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions charts/nebula-operator/crds/nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down Expand Up @@ -5199,6 +5211,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down Expand Up @@ -8008,6 +8032,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down Expand Up @@ -10844,6 +10880,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down
48 changes: 48 additions & 0 deletions config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down Expand Up @@ -5199,6 +5211,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down Expand Up @@ -8008,6 +8032,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down Expand Up @@ -10844,6 +10880,18 @@ spec:
type: string
type: object
type: array
topologySpreadConstraints:
items:
properties:
topologyKey:
type: string
whenUnsatisfiable:
type: string
required:
- topologyKey
- whenUnsatisfiable
type: object
type: array
version:
default: latest
type: string
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/component/storaged_failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ func (s *storagedFailover) checkPendingPod(nc *v1alpha1.NebulaCluster) error {
}
}
}
if isPodConditionScheduledTrue(pod.Status.Conditions) && isPodPending(pod) {
if isPodConditionScheduledTrue(pod.Status.Conditions) && isPodPending(pod) && time.Now().After(pod.CreationTimestamp.Add(time.Minute*1)) {
klog.Infof("storagd pod [%s/%s] conditions %v", nc.Namespace, podName, pod.Status.Conditions)
if err := s.clientSet.Pod().DeletePod(nc.Namespace, podName, true); err != nil {
return err
}
return utilerrors.ReconcileErrorf("waiting for pending storaged pod [%s/%s] deleted", nc.Namespace, podName)
return utilerrors.ReconcileErrorf("pending storaged pod [%s/%s] deleted, reschedule", nc.Namespace, podName)
}
}
return nil
Expand Down

0 comments on commit 832f1f2

Please sign in to comment.