Skip to content

Commit

Permalink
Application source for rendering values (#31)
Browse files Browse the repository at this point in the history
* Adding option for image pull secret

* aplication templating

* Application source in rendering values

* Nil handling

* Upgraded chart version

* removing unnecessary nil check
  • Loading branch information
ra-grover authored Jan 10, 2023
1 parent 27408f8 commit 03e78aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion charts/overwhelm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ rules:
resources:
- events
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- ""
Expand Down
11 changes: 6 additions & 5 deletions controllers/application_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 17 additions & 1 deletion controllers/generic.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit 03e78aa

Please sign in to comment.