Skip to content

Commit

Permalink
Adding option to turn on go templating of fleet values. (#1)
Browse files Browse the repository at this point in the history
feat: disablePreProcessing flagl to disable Go templating for helm values

Signed-off-by: Greg Sidelinger <[email protected]>

Co-authored-by: Raj Perera <[email protected]>
  • Loading branch information
gregsidelinger and rajiteh authored Feb 21, 2022
1 parent b191284 commit f4e269e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 31 deletions.
16 changes: 16 additions & 0 deletions charts/fleet-crd/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down Expand Up @@ -483,6 +485,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down Expand Up @@ -990,6 +994,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down Expand Up @@ -1133,6 +1139,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down Expand Up @@ -2791,6 +2799,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down Expand Up @@ -3158,6 +3168,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down Expand Up @@ -3666,6 +3678,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down Expand Up @@ -3809,6 +3823,8 @@ spec:
chart:
nullable: true
type: string
disablePreProcess:
type: boolean
force:
type: boolean
maxHistory:
Expand Down
2 changes: 2 additions & 0 deletions docs/gitrepo-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ helm:
key: values.yaml
# Override immutable resources. This could be dangerous.
force: false
# Disable go template pre-prosessing on the fleet values
disablePreProcess: false

# A paused bundle will not update downstream clusters but instead mark the bundle
# as OutOfSync. One can then manually confirm that a bundle should be deployed to
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,15 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1U
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bifurcation/mint v0.0.0-20180715133206-93c51c6ce115/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bombsimon/logrusr v1.0.0 h1:CTCkURYAt5nhCCnKH9eLShYayj2/8Kn/4Qg3QfiU+Ro=
Expand Down Expand Up @@ -437,6 +439,7 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk=
Expand Down Expand Up @@ -740,6 +743,7 @@ github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.m
github.com/gostaticanalysis/analysisutil v0.0.3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY=
github.com/gosuri/uitable v0.0.4/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo=
github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:AQwinXlbQR2HvPjQZOmDhRqsv5mZf+Jb1RnSLxcqZcI=
github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY=
github.com/goware/prefixer v0.0.0-20160118172347-395022866408 h1:Y9iQJfEqnN3/Nce9cOegemcy/9Ai5k3huT6E80F3zaw=
github.com/goware/prefixer v0.0.0-20160118172347-395022866408/go.mod h1:PE1ycukgRPJ7bJ9a1fdfQ9j8i/cEcRAoLZzbxYpNB/s=
Expand Down Expand Up @@ -899,6 +903,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
Expand Down Expand Up @@ -1007,6 +1012,7 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.3.1 h1:cCBH2gTD2K0OtLlv/Y5H01VQCqmlDxz30kS5Y5bqfLA=
github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f h1:2+myh5ml7lgEU/51gbeLHfKGNfgEQQIWrlbdaOsidbQ=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE=
Expand Down
23 changes: 12 additions & 11 deletions pkg/apis/fleet.cattle.io/v1alpha1/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,18 @@ type KustomizeOptions struct {
}

type HelmOptions struct {
Chart string `json:"chart,omitempty"`
Repo string `json:"repo,omitempty"`
ReleaseName string `json:"releaseName,omitempty"`
Version string `json:"version,omitempty"`
TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
Values *GenericMap `json:"values,omitempty"`
ValuesFrom []ValuesFrom `json:"valuesFrom,omitempty"`
Force bool `json:"force,omitempty"`
TakeOwnership bool `json:"takeOwnership,omitempty"`
MaxHistory int `json:"maxHistory,omitempty"`
ValuesFiles []string `json:"valuesFiles,omitempty"`
Chart string `json:"chart,omitempty"`
Repo string `json:"repo,omitempty"`
ReleaseName string `json:"releaseName,omitempty"`
Version string `json:"version,omitempty"`
TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
Values *GenericMap `json:"values,omitempty"`
ValuesFrom []ValuesFrom `json:"valuesFrom,omitempty"`
Force bool `json:"force,omitempty"`
TakeOwnership bool `json:"takeOwnership,omitempty"`
MaxHistory int `json:"maxHistory,omitempty"`
ValuesFiles []string `json:"valuesFiles,omitempty"`
DisablePreProcess bool `json:"disablePreProcess,omitempty"`
}

// Define helm values that can come from configmap, secret or external. Credit: https://github.com/fluxcd/helm-operator/blob/0cfea875b5d44bea995abe7324819432070dfbdc/pkg/apis/helm.fluxcd.io/v1/types_helmrelease.go#L439
Expand Down
1 change: 1 addition & 0 deletions pkg/options/calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func merge(base, next fleet.BundleDeploymentOptions) fleet.BundleDeploymentOptio
}
result.Helm.Force = result.Helm.Force || next.Helm.Force
result.Helm.TakeOwnership = result.Helm.TakeOwnership || next.Helm.TakeOwnership
result.Helm.DisablePreProcess = result.Helm.DisablePreProcess || next.Helm.DisablePreProcess
}
if next.Kustomize != nil {
if result.Kustomize == nil {
Expand Down
28 changes: 8 additions & 20 deletions pkg/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/rancher/fleet/pkg/manifest"
"github.com/rancher/fleet/pkg/options"
"github.com/rancher/fleet/pkg/summary"
"github.com/rancher/wrangler/pkg/data"
corecontrollers "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/yaml"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -219,7 +218,6 @@ func (m *Manager) Targets(fleetBundle *fleet.Bundle) (result []*Target, _ error)
if match == nil {
continue
}

opts := options.Calculate(&fleetBundle.Spec, match.Target)
templateContext := map[string]interface{}{}
if cluster.Spec.TemplateContext != nil {
Expand Down Expand Up @@ -274,27 +272,15 @@ func addClusterLabels(opts *fleet.BundleDeploymentOptions, cluster *fleet.Cluste
return
}

newValues := map[string]interface{}{
"global": map[string]interface{}{
"fleet": map[string]interface{}{
"clusterLabels": clusterLabels,
},
},
}

if opts.Helm == nil {
opts.Helm = &fleet.HelmOptions{
Values: &fleet.GenericMap{
Data: newValues,
},
}
opts.Helm = &fleet.HelmOptions{}
return nil
}

opts.Helm = opts.Helm.DeepCopy()
if opts.Helm.Values == nil || opts.Helm.Values.Data == nil {
opts.Helm.Values = &fleet.GenericMap{
Data: newValues,
Data: map[string]interface{}{},
}
return nil
}
Expand All @@ -303,12 +289,14 @@ func addClusterLabels(opts *fleet.BundleDeploymentOptions, cluster *fleet.Cluste
return err
}

templatedValues, err := processTemplateValues(opts.Helm.Values.Data, values)
if err != nil {
return err
if opts.Helm.DisablePreProcess == false {
opts.Helm.Values.Data, err = processTemplateValues(opts.Helm.Values.Data, values)
if err != nil {
return err
}
logrus.Debugf("preProcess completed for %v", opts.Helm.ReleaseName)
}

opts.Helm.Values.Data = data.MergeMaps(templatedValues, newValues)
return nil

}
Expand Down

0 comments on commit f4e269e

Please sign in to comment.