Skip to content

Commit

Permalink
support component customize the nodeSelector (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaByte875 authored Oct 25, 2021
1 parent 63927f7 commit 63f7cc4
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 2 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 @@ -260,7 +260,7 @@ func generateStatefulSet(c NebulaClusterComponentter, cm *corev1.ConfigMap, enab

podSpec := corev1.PodSpec{
SchedulerName: nc.Spec.SchedulerName,
NodeSelector: nc.Spec.NodeSelector,
NodeSelector: c.NodeSelector(),
Containers: containers,
Volumes: volumes,
ImagePullSecrets: nc.Spec.ImagePullSecrets,
Expand Down
1 change: 1 addition & 0 deletions apis/apps/v1alpha1/nebulacluster_componentter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type NebulaClusterComponentter interface {
GetPodEnvVars() []corev1.EnvVar
GetPodAnnotations() map[string]string
GetPodLabels() map[string]string
NodeSelector() map[string]string
IsHeadlessService() bool
GetServiceSpec() *ServiceSpec
GetServiceName() string
Expand Down
11 changes: 11 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_graphd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func (c *graphdComponent) GetPodLabels() map[string]string {
return c.nc.Spec.Graphd.PodSpec.Labels
}

func (c *graphdComponent) NodeSelector() map[string]string {
selector := map[string]string{}
for k, v := range c.nc.Spec.NodeSelector {
selector[k] = v
}
for k, v := range c.nc.Spec.Graphd.PodSpec.NodeSelector {
selector[k] = v
}
return selector
}

func (c *graphdComponent) IsHeadlessService() bool {
return false
}
Expand Down
11 changes: 11 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_metad.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func (c *metadComponent) GetPodLabels() map[string]string {
return c.nc.Spec.Metad.PodSpec.Labels
}

func (c *metadComponent) NodeSelector() map[string]string {
selector := map[string]string{}
for k, v := range c.nc.Spec.NodeSelector {
selector[k] = v
}
for k, v := range c.nc.Spec.Metad.PodSpec.NodeSelector {
selector[k] = v
}
return selector
}

func (c *metadComponent) IsHeadlessService() bool {
return true
}
Expand Down
11 changes: 11 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_storaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ func (c *storagedComponent) GetPodLabels() map[string]string {
return c.nc.Spec.Storaged.PodSpec.Labels
}

func (c *storagedComponent) NodeSelector() map[string]string {
selector := map[string]string{}
for k, v := range c.nc.Spec.NodeSelector {
selector[k] = v
}
for k, v := range c.nc.Spec.Storaged.PodSpec.NodeSelector {
selector[k] = v
}
return selector
}

func (c *storagedComponent) IsHeadlessService() bool {
return true
}
Expand Down
4 changes: 4 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ type PodSpec struct {

// +optional
Labels map[string]string `json:"labels,omitempty"`

// K8S nodeSelector.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// StorageClaim contains details of storages
Expand Down
7 changes: 7 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.

12 changes: 12 additions & 0 deletions config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ spec:
additionalProperties:
type: string
type: object
nodeSelector:
additionalProperties:
type: string
type: object
replicas:
format: int32
minimum: 0
Expand Down Expand Up @@ -297,6 +301,10 @@ spec:
additionalProperties:
type: string
type: object
nodeSelector:
additionalProperties:
type: string
type: object
replicas:
format: int32
minimum: 0
Expand Down Expand Up @@ -457,6 +465,10 @@ spec:
additionalProperties:
type: string
type: object
nodeSelector:
additionalProperties:
type: string
type: object
replicas:
format: int32
minimum: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func Test_defaultNebulaClusterControl_UpdateNebulaCluster(t *testing.T) {
}
}

// nolint: gocritic
func newFakeNebulaClusterControl() (
ControlInterface,
*component.FakeGraphdCluster,
Expand Down

0 comments on commit 63f7cc4

Please sign in to comment.