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

feat: kyverno operator support #485

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,16 @@ type Trivy struct {
SkipInstall bool `json:"skipInstall,omitempty"`
Namespace string `json:"namespace,omitempty"`
}

type Kyverno struct {
Enabled bool `json:"enabled,omitempty"`
SkipInstall bool `json:"skipInstall,omitempty"`
Namespace string `json:"namespace,omitempty"`
}

type Integrations struct {
Trivy *Trivy `json:"trivy,omitempty"`
Trivy *Trivy `json:"trivy,omitempty"`
Kyverno *Kyverno `json:"kyverno,omitempty"`
}

type ImagePullSecrets struct {
Expand Down
9 changes: 9 additions & 0 deletions chart/operator/templates/k8sgpt-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ spec:
skipInstall:
type: boolean
type: object
kyverno:
properties:
enabled:
type: boolean
namespace:
type: string
skipInstall:
type: boolean
type: object
type: object
kubeconfig:
description: Define the kubeconfig the Deployment must use. If empty,
Expand Down
16 changes: 14 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ module github.com/k8sgpt-ai/k8sgpt-operator

go 1.21

replace github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1 => /Users/ronaldpetty/github.com/ronaldpetty/k8sgpt-operator/api/v1alpha1
ronaldpetty marked this conversation as resolved.
Show resolved Hide resolved

replace github.com/k8sgpt-ai/k8sgpt-operator/pkg/client => /Users/ronaldpetty/github.com/ronaldpetty/k8sgpt-operator/pkg/client

replace github.com/k8sgpt-ai/k8sgpt-operator/pkg/integrations => /Users/ronaldpetty/github.com/ronaldpetty/k8sgpt-operator/pkg/integrations

replace github.com/k8sgpt-ai/k8sgpt-operator/pkg/resources => /Users/ronaldpetty/github.com/ronaldpetty/k8sgpt-operator/pkg/resources

replace github.com/k8sgpt-ai/k8sgpt-operator/pkg/sinks => /Users/ronaldpetty/github.com/ronaldpetty/k8sgpt-operator/pkg/sinks

replace github.com/k8sgpt-ai/k8sgpt-operator/pkg/utils => /Users/ronaldpetty/github.com/ronaldpetty/k8sgpt-operator/pkg/utils

require (
buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go v1.4.0-20240406062209-1cc152efbf5c.1
buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go v1.34.2-20240720172138-1b9bcd834f17.2
buf.build/gen/go/ronaldpetty/ronk8sgpt/grpc/go v1.4.0-20240727213336-017f305e80df.2
ronaldpetty marked this conversation as resolved.
Show resolved Hide resolved
buf.build/gen/go/ronaldpetty/ronk8sgpt/protocolbuffers/go v1.34.2-20240727213336-017f305e80df.2
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/prometheus/client_golang v1.19.1
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"

rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
rpc "buf.build/gen/go/ronaldpetty/ronk8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/ronaldpetty/ronk8sgpt/protocolbuffers/go/schema/v1"
"github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1"
"github.com/k8sgpt-ai/k8sgpt-operator/pkg/common"
v1 "k8s.io/api/apps/v1"
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
rpc "buf.build/gen/go/ronaldpetty/ronk8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/ronaldpetty/ronk8sgpt/protocolbuffers/go/schema/v1"
"github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1"
)

Expand Down
65 changes: 54 additions & 11 deletions pkg/client/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
rpc "buf.build/gen/go/ronaldpetty/ronk8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/ronaldpetty/ronk8sgpt/protocolbuffers/go/schema/v1"
"github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1"
)

Expand All @@ -21,21 +21,64 @@ func (c *Client) AddIntegration(config *v1alpha1.K8sGPT) error {
return err
}

if resp.Trivy.Enabled == config.Spec.Integrations.Trivy.Enabled {
fmt.Println("Skipping trivy installation, already enabled")
skipTrivy := false
skipKyverno := false

if resp.Trivy.Enabled {
if config.Spec.Integrations.Trivy != nil {
if config.Spec.Integrations.Trivy.Enabled {
fmt.Println("Skipping trivy installation, already enabled")
skipTrivy = true
}
}
} else {
ronaldpetty marked this conversation as resolved.
Show resolved Hide resolved
skipTrivy = true
}

if resp.Kyverno.Enabled {
if config.Spec.Integrations.Kyverno != nil {
if config.Spec.Integrations.Kyverno.Enabled {
fmt.Println("Skipping kyverno installation, already enabled")
skipKyverno = true
}
}
} else {
skipKyverno = true
}

if skipTrivy && skipKyverno {
return nil
}

intergrate := &schemav1.Integrations{}

var trivy *schemav1.Trivy

if config.Spec.Integrations.Trivy != nil {
trivy = &schemav1.Trivy{
Enabled: config.Spec.Integrations.Trivy.Enabled,
SkipInstall: config.Spec.Integrations.Trivy.SkipInstall,
Namespace: config.Spec.Integrations.Trivy.Namespace,
}
intergrate.Trivy = trivy
}

var kyverno *schemav1.Kyverno

if config.Spec.Integrations.Kyverno != nil {
kyverno = &schemav1.Kyverno{
Enabled: config.Spec.Integrations.Kyverno.Enabled,
SkipInstall: config.Spec.Integrations.Kyverno.SkipInstall,
Namespace: config.Spec.Integrations.Kyverno.Namespace,
}
intergrate.Kyverno = kyverno
}

// If the integration is inactive, make it active
// Equally, if the flag has been deactivated we should also account for this
// TODO: Currently this only support trivy
configUpdatereq := &schemav1.AddConfigRequest{
Integrations: &schemav1.Integrations{
Trivy: &schemav1.Trivy{
Enabled: config.Spec.Integrations.Trivy.Enabled,
SkipInstall: config.Spec.Integrations.Trivy.SkipInstall,
Namespace: config.Spec.Integrations.Trivy.Namespace,
},
},
Integrations: intergrate,
}
_, err = client.AddConfig(context.Background(), configUpdatereq)
if err != nil {
Expand Down