Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed May 9, 2024
2 parents 58035d5 + 56bb6da commit 2f11522
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions charts/deployment-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: deployment-operator
description: creates a new instance of the plural deployment operator
appVersion: 0.4.24
version: 0.4.24
appVersion: 0.4.25
version: 0.4.25
maintainers:
- name: Plural
url: https://www.plural.sh
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/yuin/gopher-lua v1.1.1
go.uber.org/zap v1.27.0
golang.org/x/net v0.23.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.14.3
k8s.io/api v0.29.2
k8s.io/apiextensions-apiserver v0.29.0
Expand Down Expand Up @@ -223,7 +224,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.29.0 // indirect
k8s.io/component-base v0.29.2 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
Expand Down
24 changes: 15 additions & 9 deletions internal/controller/constraint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package controller

import (
"context"
"encoding/json"
"fmt"

"gopkg.in/yaml.v3"

templatesv1 "github.com/open-policy-agent/frameworks/constraint/pkg/apis/templates/v1"
"github.com/open-policy-agent/gatekeeper/v3/apis/status/v1beta1"
constraintstatusv1beta1 "github.com/open-policy-agent/gatekeeper/v3/apis/status/v1beta1"
Expand All @@ -29,11 +30,11 @@ const (
)

type BundleData struct {
Description string `json:"description"`
Severity string `json:"severity"`
BundleName string `json:"bundleName"`
BundleDisplayName string `json:"bundleDisplayName"`
Remediation string `json:"remediation"`
Description string `json:"description" yaml:"description"`
Severity string `json:"severity" yaml:"severity"`
BundleName string `json:"bundleName" yaml:"bundleName"`
BundleDisplayName string `json:"bundleDisplayName" yaml:"bundleDisplayName"`
Remediation string `json:"remediation" yaml:"remediation"`
}

type StatusViolation struct {
Expand Down Expand Up @@ -86,6 +87,8 @@ func (r *ConstraintReconciler) Reconcile(ctx context.Context, req ctrl.Request)
if err != nil {
return ctrl.Result{}, err
}

logger.Info("recording constraint", "name", pca.Name)
r.Constraints[pca.Name] = pca
res, err := r.ConsoleClient.UpsertConstraints(algorithms.MapValues[string, *console.PolicyConstraintAttributes](r.Constraints))
if err != nil {
Expand Down Expand Up @@ -114,12 +117,15 @@ func GenerateAPIConstraint(instance *unstructured.Unstructured, template *templa
},
}

if template.Annotations != nil {
if annotations := instance.GetAnnotations(); annotations != nil {
var bundleData BundleData
if d, ok := template.Annotations[bundleDataAnnotation]; ok {
if err := json.Unmarshal([]byte(d), &bundleData); err != nil {
if d, ok := annotations[bundleDataAnnotation]; ok {
fmt.Printf("found bundle data: %s\n", d)
if err := yaml.Unmarshal([]byte(d), &bundleData); err != nil {
pca.Description = lo.ToPtr(bundleData.Description)
pca.Recommendation = lo.ToPtr(bundleData.Remediation)
} else {
fmt.Printf("Could not parse bundle data %s\n", err.Error())
}
}
}
Expand Down

0 comments on commit 2f11522

Please sign in to comment.