@@ -2,9 +2,10 @@ package controller
22
33import (
44 "context"
5- "encoding/json"
65 "fmt"
76
7+ "gopkg.in/yaml.v3"
8+
89 templatesv1 "github.com/open-policy-agent/frameworks/constraint/pkg/apis/templates/v1"
910 "github.com/open-policy-agent/gatekeeper/v3/apis/status/v1beta1"
1011 constraintstatusv1beta1 "github.com/open-policy-agent/gatekeeper/v3/apis/status/v1beta1"
@@ -29,11 +30,11 @@ const (
2930)
3031
3132type BundleData struct {
32- Description string `json:"description"`
33- Severity string `json:"severity"`
34- BundleName string `json:"bundleName"`
35- BundleDisplayName string `json:"bundleDisplayName"`
36- Remediation string `json:"remediation"`
33+ Description string `json:"description" yaml:"description" `
34+ Severity string `json:"severity" yaml:"severity" `
35+ BundleName string `json:"bundleName" yaml:"bundleName" `
36+ BundleDisplayName string `json:"bundleDisplayName" yaml:"bundleDisplayName" `
37+ Remediation string `json:"remediation" yaml:"remediation" `
3738}
3839
3940type StatusViolation struct {
@@ -86,6 +87,8 @@ func (r *ConstraintReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8687 if err != nil {
8788 return ctrl.Result {}, err
8889 }
90+
91+ logger .Info ("recording constraint" , "name" , pca .Name )
8992 r .Constraints [pca .Name ] = pca
9093 res , err := r .ConsoleClient .UpsertConstraints (algorithms.MapValues [string , * console.PolicyConstraintAttributes ](r .Constraints ))
9194 if err != nil {
@@ -114,12 +117,15 @@ func GenerateAPIConstraint(instance *unstructured.Unstructured, template *templa
114117 },
115118 }
116119
117- if template . Annotations != nil {
120+ if annotations := instance . GetAnnotations (); annotations != nil {
118121 var bundleData BundleData
119- if d , ok := template .Annotations [bundleDataAnnotation ]; ok {
120- if err := json .Unmarshal ([]byte (d ), & bundleData ); err != nil {
122+ if d , ok := annotations [bundleDataAnnotation ]; ok {
123+ fmt .Printf ("found bundle data: %s\n " , d )
124+ if err := yaml .Unmarshal ([]byte (d ), & bundleData ); err != nil {
121125 pca .Description = lo .ToPtr (bundleData .Description )
122126 pca .Recommendation = lo .ToPtr (bundleData .Remediation )
127+ } else {
128+ fmt .Printf ("Could not parse bundle data %s\n " , err .Error ())
123129 }
124130 }
125131 }
0 commit comments