Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove hardcoded k8sgpt image respository #272

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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
```
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
23 changes: 12 additions & 11 deletions api/v1alpha1/k8sgpt_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
},
}

Expand All @@ -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,
},
}

Expand Down
3 changes: 3 additions & 0 deletions chart/operator/templates/k8sgpt-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ spec:
type: string
type: object
type: object
repository:
default: ghcr.io/k8sgpt-ai/k8sgpt
type: string
sink:
properties:
type:
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ spec:
type: string
type: object
type: object
repository:
default: ghcr.io/k8sgpt-ai/k8gpt
type: string
sink:
properties:
type:
Expand Down
11 changes: 8 additions & 3 deletions controllers/k8sgpt_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
},
Expand Down