Skip to content

Commit

Permalink
Add the .PolicyMetadata hub template variable
Browse files Browse the repository at this point in the history
Relates:
https://issues.redhat.com/browse/ACM-13612

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
  • Loading branch information
mprahl authored and openshift-merge-bot[bot] committed Sep 12, 2024
1 parent 9a79ace commit d5e0066
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ spec:
labels:
cluster-name: {{hub .ManagedClusterName hub}}
ford.com/model: Mustang
policy-name: {{hub .PolicyMetadata.name hub}}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ spec:
labels:
cluster-name: local-cluster
ford.com/model: Mustang
policy-name: label-configmaps
name: cool-car
namespace: default
remediationAction: enforce
Expand Down
10 changes: 10 additions & 0 deletions cmd/template-resolver/utils/resolver_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
type hubTemplateCtx struct {
ManagedClusterName string
ManagedClusterLabels map[string]string
PolicyMetadata map[string]interface{}
}

type hubTemplateOptions struct {
Expand Down Expand Up @@ -147,6 +148,15 @@ func ProcessTemplate(yamlBytes []byte, hubKubeConfigPath, clusterName, hubNS str
return nil, fmt.Errorf("failed to get the ManagedCluster object for %s: %w", clusterName, err)
}

if policy.GetKind() == "Policy" {
hubTemplateOpts.ctx.PolicyMetadata = map[string]interface{}{
"annotations": policy.GetAnnotations(),
"labels": policy.GetLabels(),
"name": policy.GetName(),
"namespace": policy.GetNamespace(),
}
}

hubTemplateOpts.ctx.ManagedClusterName = clusterName
hubTemplateOpts.ctx.ManagedClusterLabels = mc.GetLabels()

Expand Down

0 comments on commit d5e0066

Please sign in to comment.