diff --git a/charts/deployment-operator/Chart.yaml b/charts/deployment-operator/Chart.yaml index b152776c..cbdf918e 100644 --- a/charts/deployment-operator/Chart.yaml +++ b/charts/deployment-operator/Chart.yaml @@ -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 diff --git a/go.mod b/go.mod index 185b9b60..55b785b5 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/internal/controller/constraint_controller.go b/internal/controller/constraint_controller.go index e2b27cfc..9fb428a8 100644 --- a/internal/controller/constraint_controller.go +++ b/internal/controller/constraint_controller.go @@ -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" @@ -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 { @@ -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 { @@ -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()) } } }