-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
- Loading branch information
1 parent
5b5fd2f
commit f75cbaf
Showing
7 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"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" | ||
"github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1" | ||
) | ||
|
||
func (c *Client) AddIntegration(config *v1alpha1.K8sGPT) error { | ||
|
||
// Check if the integration is active already | ||
client := rpc.NewServerServiceClient(c.conn) | ||
|
||
req := &schemav1.ListIntegrationsRequest{} | ||
|
||
resp, err := client.ListIntegrations(context.Background(), | ||
req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if config.Spec.Integrations.Trivy == nil { | ||
return errors.New("integrations: only Trivy is currently supported") | ||
} | ||
|
||
// Check for active integrations | ||
for _, active := range resp.Integrations { | ||
switch active { | ||
case "trivy": | ||
// Integration is active, nothing to do | ||
return nil | ||
} | ||
} | ||
// If the integration is inactive, make it active | ||
// TODO: Currently this only support trivy | ||
configUpdatereq := &schemav1.AddConfigRequest{ | ||
Integrations: &schemav1.Integrations{ | ||
Trivy: &schemav1.Trivy{ | ||
Enabled: true, | ||
SkipInstall: config.Spec.Integrations.Trivy.SkipInstall, | ||
Namespace: config.Spec.Integrations.Trivy.Namespace, | ||
}, | ||
}, | ||
} | ||
_, err = client.AddConfig(context.Background(), configUpdatereq) | ||
if err != nil { | ||
return fmt.Errorf("failed to call AddConfig RPC: %v", err) | ||
} | ||
fmt.Println("Activated integration") | ||
return nil | ||
} |