Skip to content

Commit

Permalink
Merge pull request #639 from gianlucam76/release-0.34
Browse files Browse the repository at this point in the history
Release 0.34
  • Loading branch information
gianlucam76 authored Jul 17, 2024
2 parents ea03178 + d2976f3 commit 961c3f3
Show file tree
Hide file tree
Showing 31 changed files with 233 additions and 298 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ARCH ?= $(shell go env GOARCH)
OS ?= $(shell uname -s | tr A-Z a-z)
K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= v0.34.1
TAG ?= v0.34.2

.PHONY: all
all: build
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spec:
- "--report-mode=0"
- --shard-key=
- "--v=5"
- "--version=v0.34.1"
- "--version=v0.34.2"
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: projectsveltos/addon-controller:v0.34.1
- image: projectsveltos/addon-controller:v0.34.2
name: controller
178 changes: 0 additions & 178 deletions controllers/funcmap.go

This file was deleted.

14 changes: 9 additions & 5 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,29 +1634,33 @@ func getInstantiatedValues(ctx context.Context, clusterSummary *configv1beta1.Cl
}

c := getManagementClusterClient()
valuesFrom, err := getHelmChartValuesFrom(ctx, c, clusterSummary, requestedChart, logger)
templatedValuesFrom, valuesFrom, err := getHelmChartValuesFrom(ctx, c, clusterSummary, requestedChart, logger)
if err != nil {
return nil, err
}

for k := range valuesFrom {
for k := range templatedValuesFrom {
instantiatedValuesFrom, err := instantiateTemplateValues(ctx, getManagementClusterConfig(), getManagementClusterClient(),
clusterSummary.Spec.ClusterType, clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName,
requestedChart.ChartName, valuesFrom[k], mgmtResources, logger)
requestedChart.ChartName, templatedValuesFrom[k], mgmtResources, logger)
if err != nil {
return nil, err
}
instantiatedValues += fmt.Sprintf("\n\n%s", instantiatedValuesFrom)
}

logger.V(logs.LogVerbose).Info(fmt.Sprintf("Deploying helm charts with Values %q", instantiatedValues))
for k := range valuesFrom {
instantiatedValues += fmt.Sprintf("\n\n%s", valuesFrom[k])
}

logger.V(logs.LogDebug).Info(fmt.Sprintf("Deploying helm charts with Values %q", instantiatedValues))

return chartutil.ReadValues([]byte(instantiatedValues))
}

// getHelmChartValuesFrom return key-value pair from referenced ConfigMap/Secret
func getHelmChartValuesFrom(ctx context.Context, c client.Client, clusterSummary *configv1beta1.ClusterSummary,
helmChart *configv1beta1.HelmChart, logger logr.Logger) (map[string]string, error) {
helmChart *configv1beta1.HelmChart, logger logr.Logger) (templatedValues, nonTemplatedValues map[string]string, err error) {

return getValuesFrom(ctx, c, clusterSummary, helmChart.ValuesFrom, false, logger)
}
Expand Down
33 changes: 20 additions & 13 deletions controllers/handlers_kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
"github.com/projectsveltos/libsveltos/lib/clusterproxy"
"github.com/projectsveltos/libsveltos/lib/deployer"
"github.com/projectsveltos/libsveltos/lib/funcmap"
logs "github.com/projectsveltos/libsveltos/lib/logsettings"
libsveltostemplate "github.com/projectsveltos/libsveltos/lib/template"
"github.com/projectsveltos/libsveltos/lib/utils"
Expand Down Expand Up @@ -415,27 +416,30 @@ func instantiateKustomizeSubstituteValues(ctx context.Context, clusterSummary *c

// getKustomizeSubstituteValues returns all key-value pair looking at both Values and ValuesFrom
func getKustomizeSubstituteValues(ctx context.Context, c client.Client, clusterSummary *configv1beta1.ClusterSummary,
kustomizationRef *configv1beta1.KustomizationRef, logger logr.Logger) (map[string]string, error) {
kustomizationRef *configv1beta1.KustomizationRef, logger logr.Logger) (templatedValues, nonTemplatedValues map[string]string, err error) {

values := make(map[string]string)
for k := range kustomizationRef.Values {
values[k] = kustomizationRef.Values[k]
}

// Get key-value pairs from ValuesFrom
valuesFrom, err := getKustomizeSubstituteValuesFrom(ctx, c, clusterSummary, kustomizationRef, logger)
templatedValues, nonTemplatedValues, err = getKustomizeSubstituteValuesFrom(ctx, c, clusterSummary, kustomizationRef, logger)
if err != nil {
return nil, err
return nil, nil, err
}
for k := range valuesFrom {
values[k] = valuesFrom[k]

// Values are always treated as templates. So copy the templated values here
for k := range templatedValues {
values[k] = templatedValues[k]
}

return values, nil
return values, nonTemplatedValues, nil
}

// getKustomizeSubstituteValuesFrom return key-value pair from referenced ConfigMap/Secret
func getKustomizeSubstituteValuesFrom(ctx context.Context, c client.Client, clusterSummary *configv1beta1.ClusterSummary,
kustomizationRef *configv1beta1.KustomizationRef, logger logr.Logger) (map[string]string, error) {
kustomizationRef *configv1beta1.KustomizationRef, logger logr.Logger) (templatedValues, nonTemplatedValues map[string]string, err error) {

return getValuesFrom(ctx, c, clusterSummary, kustomizationRef.ValuesFrom, true, logger)
}
Expand Down Expand Up @@ -615,18 +619,21 @@ func getKustomizedResources(ctx context.Context, c client.Client, clusterSummary
}

// Get key-value pairs from ValuesFrom
values, err := getKustomizeSubstituteValues(ctx, c, clusterSummary, kustomizationRef, logger)
templatedValues, nonTemplatedValues, err := getKustomizeSubstituteValues(ctx, c, clusterSummary, kustomizationRef, logger)
if err != nil {
return nil, nil, nil, err
}

// Get substitute values. Those are collected from Data sections of referenced ConfigMap/Secret instances.
// Those values can be expressed as template. This method collects them and instantiate those using resources in
// Those values can be expressed as template. This method instantiates those using resources in
// the managemenet cluster
instantiateSubstituteValues, err := instantiateKustomizeSubstituteValues(ctx, clusterSummary, mgmtResources, values, logger)
instantiatedSubstituteValues, err := instantiateKustomizeSubstituteValues(ctx, clusterSummary, mgmtResources, templatedValues, logger)
if err != nil {
return nil, nil, nil, err
}
for k := range nonTemplatedValues {
instantiatedSubstituteValues[k] = nonTemplatedValues[k]
}

resources := resMap.Resources()
for i := range resources {
Expand All @@ -638,11 +645,11 @@ func getKustomizedResources(ctx context.Context, c client.Client, clusterSummary
}

// Assume it is a template only if there are values to substitute
if len(instantiateSubstituteValues) > 0 {
if len(instantiatedSubstituteValues) > 0 {
// All objects coming from Kustomize output can be expressed as template. Those will be instantiated using
// substitute values first, and the resource in the management cluster later.
templateName := fmt.Sprintf("%s-substitutevalues", clusterSummary.Name)
yaml, err = instantiateResourceWithSubstituteValues(templateName, yaml, instantiateSubstituteValues, logger)
yaml, err = instantiateResourceWithSubstituteValues(templateName, yaml, instantiatedSubstituteValues, logger)
if err != nil {
msg := fmt.Sprintf("failed to instantiate resource with substitute values: %v", err)
logger.V(logs.LogInfo).Info(msg)
Expand Down Expand Up @@ -882,7 +889,7 @@ func extractTarGz(src, dest string) error {
func instantiateResourceWithSubstituteValues(templateName string, resource []byte,
substituteValues map[string]string, logger logr.Logger) ([]byte, error) {

tmpl, err := template.New(templateName).Option("missingkey=error").Funcs(ExtraFuncMap()).Parse(string(resource))
tmpl, err := template.New(templateName).Option("missingkey=error").Funcs(funcmap.SveltosFuncMap()).Parse(string(resource))
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 961c3f3

Please sign in to comment.