diff --git a/charts/overwhelm/Chart.yaml b/charts/overwhelm/Chart.yaml index 46dcf4e..d6e6a74 100644 --- a/charts/overwhelm/Chart.yaml +++ b/charts/overwhelm/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: overwhelm -version: 1.1.5 +version: 1.1.6 maintainers: - name: "Expedia Group" url: "https://github.com/ExpediaGroup/overwhelm" \ No newline at end of file diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 97e4b34..7d72dac 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -38,8 +38,10 @@ rules: resources: - events verbs: + - create - get - list + - update - watch - apiGroups: - "" diff --git a/controllers/application_controller.go b/controllers/application_controller.go index ac667c0..e61da8f 100644 --- a/controllers/application_controller.go +++ b/controllers/application_controller.go @@ -20,13 +20,14 @@ import ( "crypto/sha1" "errors" "fmt" + "regexp" + "text/template" + "time" + "github.com/fluxcd/pkg/apis/meta" "gopkg.in/yaml.v3" - "regexp" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" - "text/template" - "time" "github.com/ExpediaGroup/overwhelm/analyzer" "github.com/fluxcd/helm-controller/api/v2beta1" @@ -97,7 +98,7 @@ var log logr.Logger //+kubebuilder:rbac:groups=core,resources=pods/status,verbs=get;watch //+kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch //+kubebuilder:rbac:groups=apps,resources=replicasets,verbs=get;list;watch -//+kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch +//+kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;update;create // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. @@ -396,7 +397,7 @@ func (r *ApplicationReconciler) renderValues(application *v1.Application) error if err != nil { return err } - if err = tmpl.Execute(buf, GetPreRenderData()); err != nil { + if err = tmpl.Execute(buf, GetPreRenderData(application.GetLabels())); err != nil { return err } values[key] = buf.String() diff --git a/controllers/generic.go b/controllers/generic.go index ace1257..1b537d0 100644 --- a/controllers/generic.go +++ b/controllers/generic.go @@ -1,6 +1,8 @@ package controllers import ( + "strings" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/informers" @@ -11,7 +13,10 @@ import ( var preRenderData = make(map[string]map[string]string) +const expediaType = "k8s.expediagroup.com" + const ReferenceLabel = "overwhelm.expediagroup.com/render-values-source" +const ApplicationKey = "application" func LoadPreRenderData() { labelOptions := informers.WithTweakListOptions(func(opts *metav1.ListOptions) { @@ -44,6 +49,17 @@ func addToPrerenderData(cm *v1.ConfigMap) { } } -func GetPreRenderData() map[string]map[string]string { +func GetPreRenderData(appLabels map[string]string) map[string]map[string]string { + for label, labelValue := range appLabels { + if strings.HasPrefix(label, expediaType) { + //Initialise the map, even if there is a single label matching criteria + if preRenderData[ApplicationKey] == nil { + preRenderData[ApplicationKey] = make(map[string]string) + } + trimmedLabel := strings.Trim(strings.TrimPrefix(label, expediaType), "/") + preRenderData[ApplicationKey][trimmedLabel] = labelValue + } + } + return preRenderData }