Skip to content

Commit 56bb6da

Browse files
Bundle data description is actually keyed with (#183)
1 parent fce2a80 commit 56bb6da

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/yuin/gopher-lua v1.1.1
3232
go.uber.org/zap v1.27.0
3333
golang.org/x/net v0.23.0
34+
gopkg.in/yaml.v3 v3.0.1
3435
helm.sh/helm/v3 v3.14.3
3536
k8s.io/api v0.29.2
3637
k8s.io/apiextensions-apiserver v0.29.0
@@ -223,7 +224,6 @@ require (
223224
gopkg.in/inf.v0 v0.9.1 // indirect
224225
gopkg.in/ini.v1 v1.67.0 // indirect
225226
gopkg.in/yaml.v2 v2.4.0 // indirect
226-
gopkg.in/yaml.v3 v3.0.1 // indirect
227227
k8s.io/apiserver v0.29.0 // indirect
228228
k8s.io/component-base v0.29.2 // indirect
229229
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,6 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
526526
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
527527
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
528528
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
529-
github.com/pluralsh/console-client-go v0.5.2 h1:vDiKzZ/vPFivr9TIXSSi/6Q1nOrH4y1huE5XkrCJ3D0=
530-
github.com/pluralsh/console-client-go v0.5.2/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
531529
github.com/pluralsh/console-client-go v0.5.6 h1:8CUQco0vJehtKabVVNHAkFE4V9UI9MaMKvYNgQRrJdo=
532530
github.com/pluralsh/console-client-go v0.5.6/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
533531
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=

internal/controller/constraint_controller.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package controller
22

33
import (
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

3132
type 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

3940
type 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

Comments
 (0)