diff --git a/api/v1alpha1/k8sgpt_types.go b/api/v1alpha1/k8sgpt_types.go index 493e0f09..a32e5d73 100644 --- a/api/v1alpha1/k8sgpt_types.go +++ b/api/v1alpha1/k8sgpt_types.go @@ -98,14 +98,15 @@ type Integrations struct { type K8sGPTSpec struct { Version string `json:"version,omitempty"` // +kubebuilder:default:=ghcr.io/k8sgpt-ai/k8sgpt - Repository string `json:"repository,omitempty"` - NoCache bool `json:"noCache,omitempty"` - Filters []string `json:"filters,omitempty"` - ExtraOptions *ExtraOptionsRef `json:"extraOptions,omitempty"` - Sink *WebhookRef `json:"sink,omitempty"` - AI *AISpec `json:"ai,omitempty"` - RemoteCache *RemoteCacheRef `json:"remoteCache,omitempty"` - Integrations *Integrations `json:"integrations,omitempty"` + Repository string `json:"repository,omitempty"` + NoCache bool `json:"noCache,omitempty"` + Filters []string `json:"filters,omitempty"` + ExtraOptions *ExtraOptionsRef `json:"extraOptions,omitempty"` + Sink *WebhookRef `json:"sink,omitempty"` + AI *AISpec `json:"ai,omitempty"` + RemoteCache *RemoteCacheRef `json:"remoteCache,omitempty"` + Integrations *Integrations `json:"integrations,omitempty"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` } const ( diff --git a/api/v1alpha1/k8sgpt_types_test.go b/api/v1alpha1/k8sgpt_types_test.go index 94b45bc8..ab2c0684 100644 --- a/api/v1alpha1/k8sgpt_types_test.go +++ b/api/v1alpha1/k8sgpt_types_test.go @@ -64,6 +64,9 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() { Version: version, Repository: repository, NoCache: true, + NodeSelector: map[string]string{ + "nodepool": "management", + }, }, } @@ -88,6 +91,9 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() { Repository: repository, Version: version, NoCache: false, + NodeSelector: map[string]string{ + "nodepool": "management", + }, }, } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index f145463d..a4da0fa4 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -257,6 +257,13 @@ func (in *K8sGPTSpec) DeepCopyInto(out *K8sGPTSpec) { *out = new(Integrations) (*in).DeepCopyInto(*out) } + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new K8sGPTSpec. diff --git a/chart/operator/templates/deployment.yaml b/chart/operator/templates/deployment.yaml index b6575099..adf957c5 100644 --- a/chart/operator/templates/deployment.yaml +++ b/chart/operator/templates/deployment.yaml @@ -102,3 +102,6 @@ spec: runAsNonRoot: true serviceAccountName: {{ include "chart.fullname" . }}-controller-manager terminationGracePeriodSeconds: 10 + {{- if .Values.controllerManager.nodeSelector }} + nodeSelector: {{ toYaml .Values.controllerManager.nodeSelector | nindent 8 }} + {{- end }} diff --git a/chart/operator/templates/k8sgpt-crd.yaml b/chart/operator/templates/k8sgpt-crd.yaml index 5facd8da..5346832f 100644 --- a/chart/operator/templates/k8sgpt-crd.yaml +++ b/chart/operator/templates/k8sgpt-crd.yaml @@ -98,6 +98,10 @@ spec: type: object noCache: type: boolean + nodeSelector: + additionalProperties: + type: string + type: object remoteCache: properties: azure: diff --git a/chart/operator/values.yaml b/chart/operator/values.yaml index 099b3ae4..5a6c8a01 100644 --- a/chart/operator/values.yaml +++ b/chart/operator/values.yaml @@ -48,6 +48,10 @@ controllerManager: cpu: 10m memory: 64Mi replicas: 1 + ## Node labels for pod assignment + ## ref: https://kubernetes.io/docs/user-guide/node-selection/ + # + nodeSelector: {} kubernetesClusterDomain: cluster.local metricsService: ports: diff --git a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml index f2642501..d4ac6eaa 100644 --- a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml +++ b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml @@ -98,6 +98,10 @@ spec: type: object noCache: type: boolean + nodeSelector: + additionalProperties: + type: string + type: object remoteCache: properties: azure: diff --git a/pkg/resources/k8sgpt.go b/pkg/resources/k8sgpt.go index 4d9f4845..fb7bbe3e 100644 --- a/pkg/resources/k8sgpt.go +++ b/pkg/resources/k8sgpt.go @@ -261,6 +261,7 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) { Name: "k8sgpt-vol", }, }, + NodeSelector: config.Spec.NodeSelector, }, }, },