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 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
10 changes: 9 additions & 1 deletion api/v1alpha1/k8sgpt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,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 @@ -122,6 +122,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
9 changes: 9 additions & 0 deletions config/crd/bases/core.k8sgpt.ai_k8sgpts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ spec:
type: array
integrations:
properties:
kyverno:
properties:
enabled:
type: boolean
namespace:
type: string
skipInstall:
type: boolean
type: object
trivy:
properties:
enabled:
Expand Down
61 changes: 52 additions & 9 deletions pkg/client/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,64 @@
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 {

Check failure on line 38 in pkg/client/integration.go

View workflow job for this annotation

GitHub Actions / build

resp.Kyverno undefined (type *schemav1.ListIntegrationsResponse has no field or method Kyverno)
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

Check failure on line 66 in pkg/client/integration.go

View workflow job for this annotation

GitHub Actions / build

undefined: schemav1.Kyverno

if config.Spec.Integrations.Kyverno != nil {
kyverno = &schemav1.Kyverno{

Check failure on line 69 in pkg/client/integration.go

View workflow job for this annotation

GitHub Actions / build

undefined: schemav1.Kyverno
Enabled: config.Spec.Integrations.Kyverno.Enabled,
SkipInstall: config.Spec.Integrations.Kyverno.SkipInstall,
Namespace: config.Spec.Integrations.Kyverno.Namespace,
}
intergrate.Kyverno = kyverno

Check failure on line 74 in pkg/client/integration.go

View workflow job for this annotation

GitHub Actions / build

intergrate.Kyverno undefined (type *schemav1.Integrations has no field or method 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
Loading