diff --git a/README.md b/README.md index ef1a8d50..0a2feb6c 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,8 @@ spec: # anonymized: false # language: english noCache: false - version: v0.3.17 + repository: ghcr.io/k8sgpt-ai/k8gpt + version: v0.3.8 #integrations: # trivy: # enabled: true @@ -101,14 +102,16 @@ metadata: name: k8sgpt-sample namespace: k8sgpt-operator-system spec: - model: gpt-3.5-turbo - backend: openai + ai: + model: gpt-3.5-turbo + backend: openai + enabled: true + secret: + name: k8sgpt-sample-secret + key: openai-api-key noCache: false - version: v0.3.0 - enableAI: true - secret: - name: k8sgpt-sample-secret - key: openai-api-key + repository: ghcr.io/k8sgpt-ai/k8gpt + version: v0.3.8 remoteCache: credentials: name: k8sgpt-sample-cache-secret @@ -143,14 +146,16 @@ metadata: name: k8sgpt-sample namespace: k8sgpt-operator-system spec: - model: gpt-3.5-turbo - backend: openai + ai: + model: gpt-3.5-turbo + backend: openai + enabled: true + secret: + name: k8sgpt-sample-secret + key: openai-api-key noCache: false - version: v0.3.0 - enableAI: true - secret: - name: k8sgpt-sample-secret - key: openai-api-key + repository: ghcr.io/k8sgpt-ai/k8gpt + version: v0.3.8 remoteCache: credentials: name: k8sgpt-sample-cache-secret @@ -194,6 +199,7 @@ spec: baseUrl: https://k8sgpt.openai.azure.com/ engine: llm noCache: false + repository: ghcr.io/k8sgpt-ai/k8gpt version: v0.3.8 EOF ``` @@ -224,6 +230,7 @@ spec: backend: localai baseUrl: http://local-ai.local-ai.svc.cluster.local:8080/v1 noCache: false + repository: ghcr.io/k8sgpt-ai/k8gpt version: v0.3.8 EOF ``` diff --git a/api/v1alpha1/k8sgpt_types.go b/api/v1alpha1/k8sgpt_types.go index d20c0924..7c1303f4 100644 --- a/api/v1alpha1/k8sgpt_types.go +++ b/api/v1alpha1/k8sgpt_types.go @@ -96,7 +96,9 @@ type Integrations struct { // K8sGPTSpec defines the desired state of K8sGPT type K8sGPTSpec struct { - Version string `json:"version,omitempty"` + Version string `json:"version,omitempty"` + // +kubebuilder:default:=ghcr.io/k8sgpt-ai/k8gpt + Repository string `json:"repository,omitempty"` NoCache bool `json:"noCache,omitempty"` Filters []string `json:"filters,omitempty"` ExtraOptions *ExtraOptionsRef `json:"extraOptions,omitempty"` diff --git a/api/v1alpha1/k8sgpt_types_test.go b/api/v1alpha1/k8sgpt_types_test.go index 837a4196..94b45bc8 100644 --- a/api/v1alpha1/k8sgpt_types_test.go +++ b/api/v1alpha1/k8sgpt_types_test.go @@ -34,11 +34,12 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() { Key: "k8s-gpt", } - kind = "K8sGPT" - baseUrl = "https://api.k8s-gpt.localhost" - model = "345M" - version = "v1alpha1" - language = "english" + kind = "K8sGPT" + baseUrl = "https://api.k8s-gpt.localhost" + model = "345M" + repository = "ghcr.io/k8sgpt-ai/k8sgpt" + version = "v1alpha1" + language = "english" Namespace = "k8sGPT" @@ -60,9 +61,9 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() { Anonymize: true, Language: language, }, - Version: version, - - NoCache: true, + Version: version, + Repository: repository, + NoCache: true, }, } @@ -84,9 +85,9 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() { Anonymize: false, Language: language, }, - Version: version, - - NoCache: false, + Repository: repository, + Version: version, + NoCache: false, }, } diff --git a/chart/operator/templates/k8sgpt-crd.yaml b/chart/operator/templates/k8sgpt-crd.yaml index 73b298a3..789b33d0 100644 --- a/chart/operator/templates/k8sgpt-crd.yaml +++ b/chart/operator/templates/k8sgpt-crd.yaml @@ -114,6 +114,9 @@ spec: type: string type: object type: object + repository: + default: ghcr.io/k8sgpt-ai/k8sgpt + type: string sink: properties: type: diff --git a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml index 70517509..4a6ceed6 100644 --- a/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml +++ b/config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml @@ -126,6 +126,9 @@ spec: type: string type: object type: object + repository: + default: ghcr.io/k8sgpt-ai/k8gpt + type: string sink: properties: type: diff --git a/controllers/k8sgpt_controller.go b/controllers/k8sgpt_controller.go index dccfd350..d5446f44 100644 --- a/controllers/k8sgpt_controller.go +++ b/controllers/k8sgpt_controller.go @@ -139,11 +139,16 @@ func (r *K8sGPTReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr // Check the version of the deployment image matches the version set in the K8sGPT CR imageURI := deployment.Spec.Template.Spec.Containers[0].Image - imageVersion := strings.Split(imageURI, ":")[1] - if imageVersion != k8sgptConfig.Spec.Version { + + image := strings.Split(imageURI, ":") + imageRepository := image[0] + imageVersion := image[1] + + // if one of repository or tag is changed, we need to update the deployment + if imageRepository != k8sgptConfig.Spec.Repository || imageVersion != k8sgptConfig.Spec.Version { // Update the deployment image deployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s", - strings.Split(imageURI, ":")[0], k8sgptConfig.Spec.Version) + imageRepository, k8sgptConfig.Spec.Version) err = r.Update(ctx, &deployment) if err != nil { k8sgptReconcileErrorCount.Inc() diff --git a/pkg/resources/k8sgpt.go b/pkg/resources/k8sgpt.go index bda75ca5..4d9f4845 100644 --- a/pkg/resources/k8sgpt.go +++ b/pkg/resources/k8sgpt.go @@ -174,6 +174,7 @@ func GetClusterRole(config v1alpha1.K8sGPT) (*r1.ClusterRole, error) { func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) { // Create deployment + image := config.Spec.Repository + ":" + config.Spec.Version replicas := int32(1) deployment := appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -209,7 +210,7 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) { { Name: "k8sgpt", ImagePullPolicy: corev1.PullAlways, - Image: "ghcr.io/k8sgpt-ai/k8sgpt:" + config.Spec.Version, + Image: image, Args: []string{ "serve", },