Skip to content

Commit

Permalink
fix: change backOff default enabled value to false (#541)
Browse files Browse the repository at this point in the history
* fix: change backoff enalbe default to false

Signed-off-by: JuHyung-Son <[email protected]>

* doc: add backOff in example, linting

Signed-off-by: JuHyung-Son <[email protected]>

---------

Signed-off-by: JuHyung-Son <[email protected]>
  • Loading branch information
JuHyung-Son authored Oct 21, 2024
1 parent 3fc3476 commit 2abd0e7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ helm install release k8sgpt/k8sgpt-operator -n k8sgpt-operator-system --create-n
1. Install the operator from the [Installation](#installation) section.

2. Create secret:
```sh

```sh
kubectl create secret generic k8sgpt-sample-secret --from-literal=openai-api-key=$OPENAI_TOKEN -n k8sgpt-operator-system
```

3. Apply the K8sGPT configuration object:

```sh
kubectl apply -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
Expand All @@ -45,6 +47,9 @@ spec:
secret:
name: k8sgpt-sample-secret
key: openai-api-key
# backOff:
# enabled: false
# maxRetries: 5
# anonymized: false
# language: english
# proxyEndpoint: https://10.255.30.150 # use proxyEndpoint to setup backend through an HTTP/HTTPS proxy
Expand All @@ -70,7 +75,7 @@ EOF
```

4. Once the custom resource has been applied the K8sGPT-deployment will be installed and
you will be able to see the Results objects of the analysis after some minutes (if there are any issues in your cluster):
you will be able to see the Results objects of the analysis after some minutes (if there are any issues in your cluster):

```bash
❯ kubectl get results -o json | jq .
Expand Down Expand Up @@ -109,7 +114,6 @@ capi-quickstart-kubeconfig Opaque 1 8s
>
> If your setup requires the least privilege approach,
> a different `kubeconfig` must be provided since the Cluster API generated one is bounded to the `admin` user which has `clustr-admin` permissions.
Once you have a valid `kubeconfig`, a `k8sgpt` instance can be created as it follows.
Expand Down Expand Up @@ -158,12 +162,14 @@ as well as keeping confidentiality about the AI backend driver credentials.
1. Install the operator from the [Installation](#installation) section.
2. Create secret:
```sh
kubectl create secret generic k8sgpt-sample-cache-secret --from-literal=azure_client_id=<AZURE_CLIENT_ID> --from-literal=azure_tenant_id=<AZURE_TENANT_ID> --from-literal=azure_client_secret=<AZURE_CLIENT_SECRET> -n k8sgpt-
operator-system
```
3. Apply the K8sGPT configuration object:
```
kubectl apply -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
Expand All @@ -184,7 +190,7 @@ spec:
version: v0.3.41
remoteCache:
credentials:
name: k8sgpt-sample-cache-secret
name: k8sgpt-sample-cache-secret
azure:
# Storage account must already exist
storageAccount: "account_name"
Expand All @@ -194,20 +200,21 @@ EOF
</details>
<details>
<summary>S3</summary>
1. Install the operator from the [Installation](#installation) section.
2. Create secret:
```sh
kubectl create secret generic k8sgpt-sample-cache-secret --from-literal=aws_access_key_id=<AWS_ACCESS_KEY_ID> --from-literal=aws_secret_access_key=<AWS_SECRET_ACCESS_KEY> -n k8sgpt-
operator-system
```
3. Apply the K8sGPT configuration object:
```
kubectl apply -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
Expand Down Expand Up @@ -239,19 +246,20 @@ EOF
## Other AI Backend Examples
<details>
<summary>AzureOpenAI</summary>
1. Install the operator from the [Installation](#installation) section.
2. Create secret:
```sh
```sh
kubectl create secret generic k8sgpt-sample-secret --from-literal=azure-api-key=$AZURE_TOKEN -n k8sgpt-operator-system
```
3. Apply the K8sGPT configuration object:
```
kubectl apply -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
Expand Down Expand Up @@ -284,13 +292,15 @@ EOF
1. Install the operator from the [Installation](#installation) section.
2. When running on AWS, you have a number of ways to give permission to the managed K8sGPT workload to access Amazon Bedrock.
* Grant access to Bedrock using the Kubernetes Service Account. This is the [best practices method for assigning permissions to Kubernetes Pods](https://aws.github.io/aws-eks-best-practices/security/docs/iam/#identities-and-credentials-for-eks-pods). There are a few ways to do this:
* On Amazon EKS, using [EKS Pod Identity](https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html)
* On Amazon EKS, using [IAM Roles for Service Accounts (IRSA)](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html)
* On self-managed Kubernetes, using IAM Roles for Service Accounts (IRSA) with the [Pod Identity Webhook](https://github.com/aws/amazon-eks-pod-identity-webhook)
* Grant access to Bedrock using AWS credentials in a Kubernetes Secret. Note this goes [against AWS best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-workloads-use-roles) and should be used with caution.
- Grant access to Bedrock using the Kubernetes Service Account. This is the [best practices method for assigning permissions to Kubernetes Pods](https://aws.github.io/aws-eks-best-practices/security/docs/iam/#identities-and-credentials-for-eks-pods). There are a few ways to do this:
- On Amazon EKS, using [EKS Pod Identity](https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html)
- On Amazon EKS, using [IAM Roles for Service Accounts (IRSA)](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html)
- On self-managed Kubernetes, using IAM Roles for Service Accounts (IRSA) with the [Pod Identity Webhook](https://github.com/aws/amazon-eks-pod-identity-webhook)
- Grant access to Bedrock using AWS credentials in a Kubernetes Secret. Note this goes [against AWS best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-workloads-use-roles) and should be used with caution.
To grant access to Bedrock using a Kubernetes Service account, create an IAM role with Bedrock permissions. An example policy is included below:
```
{
"Version": "2012-10-17",
Expand All @@ -308,10 +318,13 @@ To grant access to Bedrock using a Kubernetes Service account, create an IAM rol
```
To grant access to Bedrock using AWS credentials in a Kubernetes secret you can create a secret:
```sh
```sh
kubectl create secret generic bedrock-sample-secret --from-literal=AWS_ACCESS_KEY_ID="$(echo $AWS_ACCESS_KEY_ID)" --from-literal=AWS_SECRET_ACCESS_KEY="$(echo $AWS_SECRET_ACCESS_KEY)" -n k8sgpt-operator-system
```
3. Apply the K8sGPT configuration object:
```
kubectl apply -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
Expand Down Expand Up @@ -339,12 +352,12 @@ EOF
<summary>LocalAI</summary>
1. Install the operator from the [Installation](#installation) section.
2. Follow the [LocalAI installation guide](https://github.com/go-skynet/helm-charts#readme) to install LocalAI. (*No OpenAI secret is required when using LocalAI*).
2. Follow the [LocalAI installation guide](https://github.com/go-skynet/helm-charts#readme) to install LocalAI. (_No OpenAI secret is required when using LocalAI_).
3. Apply the K8sGPT configuration object:
```sh
kubectl apply -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
Expand All @@ -363,7 +376,8 @@ spec:
version: v0.3.41
EOF
```
Note: ensure that the value of `baseUrl` is a properly constructed [DNS name](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services) for the LocalAI Service. It should take the form: `http://local-ai.<namespace_local_ai_was_installed_in>.svc.cluster.local:8080/v1`.
Note: ensure that the value of `baseUrl` is a properly constructed [DNS name](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services) for the LocalAI Service. It should take the form: `http://local-ai.<namespace_local_ai_was_installed_in>.svc.cluster.local:8080/v1`.
1. Same as step 4. in the example above.
Expand Down Expand Up @@ -409,16 +423,16 @@ Optional parameters available for sink.
('type', 'webhook' are required parameters.)
| tool | channel | icon_url | username |
|------------|---------|----------|----------|
| ---------- | ------- | -------- | -------- |
| Slack | | | |
| Mattermost | ✔️ | ✔️ | ✔️ |
| Mattermost | ✔️ | ✔️ | ✔️ |
</details>
## Helm values
For details please see [here](chart/operator/values.yaml)
## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fk8sgpt-ai%2Fk8sgpt-operator.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fk8sgpt-ai%2Fk8sgpt-operator?ref=badge_large)
2 changes: 1 addition & 1 deletion api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type WebhookRef struct {
}

type BackOff struct {
// +kubebuilder:default:=true
// +kubebuilder:default:=false
Enabled bool `json:"enabled"`
// +kubebuilder:default:=5
MaxRetries int `json:"maxRetries"`
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/k8sgpt_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() {
Key: "k8s-gpt",
}
backOff = BackOff{
Enabled: true,
Enabled: false,
MaxRetries: 5,
}
kind = "K8sGPT"
Expand Down Expand Up @@ -134,7 +134,7 @@ var _ = Describe("The test cases for the K8sGPT CRDs", func() {
Expect(k8sGPTObject.APIVersion).Should(Equal(GroupVersion.String()))
Expect(k8sGPTObject.Spec.AI.Enabled).Should(Equal(true))

//get K8sGPT CRD by resource name
// get K8sGPT CRD by resource name
Expect(fakeClient.Get(ctx, types.NamespacedName{Name: "k8s-gpt-2", Namespace: Namespace}, &k8sGPTObject)).Should(Succeed())
})

Expand Down
2 changes: 1 addition & 1 deletion chart/operator/templates/k8sgpt-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
backOff:
properties:
enabled:
default: true
default: false
type: boolean
maxRetries:
default: 5
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
backOff:
properties:
enabled:
default: true
default: false
type: boolean
maxRetries:
default: 5
Expand Down
10 changes: 5 additions & 5 deletions controllers/configure_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@ func (step *ConfigureStep) execute(instance *K8sGPTInstance) (ctrl.Result, error
instance.logger.Info("ending ConfigureStep")

return step.next.execute(instance)

}

func (step *ConfigureStep) setNext(next K8sGPT) {
step.next = next
}

func (step *ConfigureStep) configureBackoff(instance *K8sGPTInstance) error {

instance.k8sgptConfig.Spec.AI.BackOff = &corev1alpha1.BackOff{
Enabled: true,
Enabled: false,
MaxRetries: 5,
}
return instance.r.Update(instance.ctx, instance.k8sgptConfig)
Expand All @@ -74,8 +72,10 @@ func (step *ConfigureStep) configureBackoff(instance *K8sGPTInstance) error {
func (step *ConfigureStep) getDeployment(instance *K8sGPTInstance) (*v1.Deployment, error) {
deployment := v1.Deployment{}

err := instance.r.Get(instance.ctx, client.ObjectKey{Namespace: instance.k8sgptConfig.Namespace,
Name: instance.k8sgptConfig.Name}, &deployment)
err := instance.r.Get(instance.ctx, client.ObjectKey{
Namespace: instance.k8sgptConfig.Namespace,
Name: instance.k8sgptConfig.Name,
}, &deployment)

if client.IgnoreNotFound(err) != nil {
return &deployment, err
Expand Down

0 comments on commit 2abd0e7

Please sign in to comment.