Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo: MgtmResources to MgmtResources #466

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c
return nil, nil, err
}

var mgtmResources map[string]*unstructured.Unstructured
mgtmResources, err = collectMgmtResources(ctx, clusterSummary)
var mgmtResources map[string]*unstructured.Unstructured
mgmtResources, err = collectMgmtResources(ctx, clusterSummary)
if err != nil {
return nil, nil, err
}
Expand All @@ -485,7 +485,7 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c

var report *configv1alpha1.ReleaseReport
var currentRelease *releaseInfo
currentRelease, report, err = handleChart(ctx, clusterSummary, mgtmResources, currentChart, kubeconfig, logger)
currentRelease, report, err = handleChart(ctx, clusterSummary, mgmtResources, currentChart, kubeconfig, logger)
if err != nil {
return nil, nil, err
}
Expand All @@ -512,12 +512,12 @@ func walkChartsAndDeploy(ctx context.Context, c client.Client, clusterSummary *c
}

func handleInstall(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, currentChart *configv1alpha1.HelmChart,
mgmtResources map[string]*unstructured.Unstructured, currentChart *configv1alpha1.HelmChart,
kubeconfig string, logger logr.Logger) (*configv1alpha1.ReleaseReport, error) {

var report *configv1alpha1.ReleaseReport
logger.V(logs.LogDebug).Info("install helm release")
err := doInstallRelease(ctx, clusterSummary, mgtmResources, currentChart, kubeconfig, logger)
err := doInstallRelease(ctx, clusterSummary, mgmtResources, currentChart, kubeconfig, logger)
if err != nil {
return nil, err
}
Expand All @@ -529,13 +529,13 @@ func handleInstall(ctx context.Context, clusterSummary *configv1alpha1.ClusterSu
}

func handleUpgrade(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, currentChart *configv1alpha1.HelmChart,
mgmtResources map[string]*unstructured.Unstructured, currentChart *configv1alpha1.HelmChart,
currentRelease *releaseInfo, kubeconfig string,
logger logr.Logger) (*configv1alpha1.ReleaseReport, error) {

var report *configv1alpha1.ReleaseReport
logger.V(logs.LogDebug).Info("upgrade helm release")
err := doUpgradeRelease(ctx, clusterSummary, mgtmResources, currentChart, kubeconfig, logger)
err := doUpgradeRelease(ctx, clusterSummary, mgmtResources, currentChart, kubeconfig, logger)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -581,7 +581,7 @@ func handleUninstall(clusterSummary *configv1alpha1.ClusterSummary, currentChart
}

func handleChart(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, currentChart *configv1alpha1.HelmChart,
mgmtResources map[string]*unstructured.Unstructured, currentChart *configv1alpha1.HelmChart,
kubeconfig string, logger logr.Logger) (*releaseInfo, *configv1alpha1.ReleaseReport, error) {

currentRelease, err := getReleaseInfo(currentChart.ReleaseName,
Expand All @@ -599,7 +599,7 @@ func handleChart(ctx context.Context, clusterSummary *configv1alpha1.ClusterSumm
}

if shouldInstall(currentRelease, currentChart) {
report, err = handleInstall(ctx, clusterSummary, mgtmResources, currentChart, kubeconfig, logger)
report, err = handleInstall(ctx, clusterSummary, mgmtResources, currentChart, kubeconfig, logger)
if err != nil {
return nil, nil, err
}
Expand All @@ -608,7 +608,7 @@ func handleChart(ctx context.Context, clusterSummary *configv1alpha1.ClusterSumm
return nil, nil, err
}
} else if shouldUpgrade(currentRelease, currentChart, clusterSummary) {
report, err = handleUpgrade(ctx, clusterSummary, mgtmResources, currentChart, currentRelease, kubeconfig, logger)
report, err = handleUpgrade(ctx, clusterSummary, mgmtResources, currentChart, currentRelease, kubeconfig, logger)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -1037,7 +1037,7 @@ func shouldUninstall(currentRelease *releaseInfo, requestedChart *configv1alpha1
// doInstallRelease installs helm release in the CAPI Cluster.
// No action in DryRun mode.
func doInstallRelease(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, requestedChart *configv1alpha1.HelmChart,
mgmtResources map[string]*unstructured.Unstructured, requestedChart *configv1alpha1.HelmChart,
kubeconfig string, logger logr.Logger) error {

// No-op in DryRun mode
Expand All @@ -1059,7 +1059,7 @@ func doInstallRelease(ctx context.Context, clusterSummary *configv1alpha1.Cluste
}

var values chartutil.Values
values, err = getInstantiatedValues(ctx, clusterSummary, mgtmResources, requestedChart, logger)
values, err = getInstantiatedValues(ctx, clusterSummary, mgmtResources, requestedChart, logger)
if err != nil {
return err
}
Expand Down Expand Up @@ -1094,7 +1094,7 @@ func doUninstallRelease(clusterSummary *configv1alpha1.ClusterSummary, requested
// doUpgradeRelease upgrades helm release in the CAPI Cluster.
// No action in DryRun mode.
func doUpgradeRelease(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, requestedChart *configv1alpha1.HelmChart,
mgmtResources map[string]*unstructured.Unstructured, requestedChart *configv1alpha1.HelmChart,
kubeconfig string, logger logr.Logger) error {

// No-op in DryRun mode
Expand All @@ -1116,7 +1116,7 @@ func doUpgradeRelease(ctx context.Context, clusterSummary *configv1alpha1.Cluste
}

var values chartutil.Values
values, err = getInstantiatedValues(ctx, clusterSummary, mgtmResources, requestedChart, logger)
values, err = getInstantiatedValues(ctx, clusterSummary, mgmtResources, requestedChart, logger)
if err != nil {
return err
}
Expand Down Expand Up @@ -1421,12 +1421,12 @@ func updateClusterReportWithHelmReports(ctx context.Context, c client.Client,
}

func getInstantiatedValues(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, requestedChart *configv1alpha1.HelmChart,
mgmtResources map[string]*unstructured.Unstructured, requestedChart *configv1alpha1.HelmChart,
logger logr.Logger) (chartutil.Values, error) {

instantiatedValues, err := instantiateTemplateValues(ctx, getManagementClusterConfig(), getManagementClusterClient(),
clusterSummary.Spec.ClusterType, clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName,
requestedChart.ChartName, requestedChart.Values, mgtmResources, logger)
requestedChart.ChartName, requestedChart.Values, mgmtResources, logger)
if err != nil {
return nil, err
}
Expand Down
36 changes: 18 additions & 18 deletions controllers/handlers_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func createNamespace(ctx context.Context, clusterClient client.Client,
// and kind.group::name for cluster wide policies.
func deployContentOfConfigMap(ctx context.Context, deployingToMgmtCluster bool, destConfig *rest.Config,
destClient client.Client, configMap *corev1.ConfigMap, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, logger logr.Logger,
mgmtResources map[string]*unstructured.Unstructured, logger logr.Logger,
) ([]configv1alpha1.ResourceReport, error) {

return deployContent(ctx, deployingToMgmtCluster, destConfig, destClient, configMap, configMap.Data,
clusterSummary, mgtmResources, logger)
clusterSummary, mgmtResources, logger)
}

// deployContentOfSecret deploys policies contained in a Secret.
Expand All @@ -115,7 +115,7 @@ func deployContentOfConfigMap(ctx context.Context, deployingToMgmtCluster bool,
// and kind.group::name for cluster wide policies.
func deployContentOfSecret(ctx context.Context, deployingToMgmtCluster bool, destConfig *rest.Config,
destClient client.Client, secret *corev1.Secret, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, logger logr.Logger,
mgmtResources map[string]*unstructured.Unstructured, logger logr.Logger,
) ([]configv1alpha1.ResourceReport, error) {

data := make(map[string]string)
Expand All @@ -124,12 +124,12 @@ func deployContentOfSecret(ctx context.Context, deployingToMgmtCluster bool, des
}

return deployContent(ctx, deployingToMgmtCluster, destConfig, destClient, secret, data,
clusterSummary, mgtmResources, logger)
clusterSummary, mgmtResources, logger)
}

func deployContentOfSource(ctx context.Context, deployingToMgmtCluster bool, destConfig *rest.Config,
destClient client.Client, source client.Object, path string, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, logger logr.Logger,
mgmtResources map[string]*unstructured.Unstructured, logger logr.Logger,
) ([]configv1alpha1.ResourceReport, error) {

s := source.(sourcev1.Source)
Expand Down Expand Up @@ -161,7 +161,7 @@ func deployContentOfSource(ctx context.Context, deployingToMgmtCluster bool, des
}

return deployContent(ctx, deployingToMgmtCluster, destConfig, destClient, source, content,
clusterSummary, mgtmResources, logger)
clusterSummary, mgmtResources, logger)
}

func readFiles(dir string) (map[string]string, error) {
Expand Down Expand Up @@ -233,11 +233,11 @@ func instantiateTemplate(referencedObject client.Object, logger logr.Logger) boo
// and kind.group::name for cluster wide policies.
func deployContent(ctx context.Context, deployingToMgmtCluster bool, destConfig *rest.Config, destClient client.Client,
referencedObject client.Object, data map[string]string, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, logger logr.Logger,
mgmtResources map[string]*unstructured.Unstructured, logger logr.Logger,
) (reports []configv1alpha1.ResourceReport, err error) {

instantiateTemplate := instantiateTemplate(referencedObject, logger)
resources, err := collectContent(ctx, clusterSummary, mgtmResources, data, instantiateTemplate, logger)
resources, err := collectContent(ctx, clusterSummary, mgmtResources, data, instantiateTemplate, logger)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -442,7 +442,7 @@ func removeCommentsAndEmptyLines(text string) string {
// or multiple policies separated by '---'
// Returns an error if one occurred. Otherwise it returns a slice of *unstructured.Unstructured.
func collectContent(ctx context.Context, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, data map[string]string,
mgmtResources map[string]*unstructured.Unstructured, data map[string]string,
instantiateTemplate bool, logger logr.Logger,
) ([]*unstructured.Unstructured, error) {

Expand All @@ -461,7 +461,7 @@ func collectContent(ctx context.Context, clusterSummary *configv1alpha1.ClusterS
if instantiateTemplate {
instance, err := instantiateTemplateValues(ctx, getManagementClusterConfig(), getManagementClusterClient(),
clusterSummary.Spec.ClusterType, clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName,
clusterSummary.GetName(), section, mgtmResources, logger)
clusterSummary.GetName(), section, mgmtResources, logger)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -661,8 +661,8 @@ func deployReferencedObjects(ctx context.Context, c client.Client, remoteConfig
return nil, nil, err
}

var mgtmResources map[string]*unstructured.Unstructured
mgtmResources, err = collectMgmtResources(ctx, clusterSummary)
var mgmtResources map[string]*unstructured.Unstructured
mgmtResources, err = collectMgmtResources(ctx, clusterSummary)
if err != nil {
return nil, nil, err
}
Expand All @@ -680,15 +680,15 @@ func deployReferencedObjects(ctx context.Context, c client.Client, remoteConfig
}
}
tmpResourceReports, err = deployObjects(ctx, true, c, localConfig, objectsToDeployLocally, clusterSummary,
mgtmResources, logger)
mgmtResources, logger)
localReports = append(localReports, tmpResourceReports...)
if err != nil {
return localReports, nil, err
}

// Deploy all resources that need to be deployed in the managed cluster
tmpResourceReports, err = deployObjects(ctx, false, remoteClient, remoteConfig, objectsToDeployRemotely, clusterSummary,
mgtmResources, logger)
mgmtResources, logger)
remoteReports = append(remoteReports, tmpResourceReports...)
if err != nil {
return localReports, remoteReports, err
Expand All @@ -700,7 +700,7 @@ func deployReferencedObjects(ctx context.Context, c client.Client, remoteConfig
// deployObjects deploys content of referencedObjects
func deployObjects(ctx context.Context, deployingToMgmtCluster bool, destClient client.Client, destConfig *rest.Config,
referencedObjects []client.Object, clusterSummary *configv1alpha1.ClusterSummary,
mgtmResources map[string]*unstructured.Unstructured, logger logr.Logger,
mgmtResources map[string]*unstructured.Unstructured, logger logr.Logger,
) (reports []configv1alpha1.ResourceReport, err error) {

for i := range referencedObjects {
Expand All @@ -711,22 +711,22 @@ func deployObjects(ctx context.Context, deployingToMgmtCluster bool, destClient
l.V(logs.LogDebug).Info("deploying ConfigMap content")
tmpResourceReports, err =
deployContentOfConfigMap(ctx, deployingToMgmtCluster, destConfig, destClient, configMap,
clusterSummary, mgtmResources, l)
clusterSummary, mgmtResources, l)
} else if referencedObjects[i].GetObjectKind().GroupVersionKind().Kind == string(libsveltosv1alpha1.SecretReferencedResourceKind) {
secret := referencedObjects[i].(*corev1.Secret)
l := logger.WithValues("secretNamespace", secret.Namespace, "secretName", secret.Name)
l.V(logs.LogDebug).Info("deploying Secret content")
tmpResourceReports, err =
deployContentOfSecret(ctx, deployingToMgmtCluster, destConfig, destClient, secret,
clusterSummary, mgtmResources, l)
clusterSummary, mgmtResources, l)
} else {
source := referencedObjects[i]
logger.V(logs.LogDebug).Info("deploying Source content")
annotations := source.GetAnnotations()
path := annotations[pathAnnotation]
tmpResourceReports, err =
deployContentOfSource(ctx, deployingToMgmtCluster, destConfig, destClient, source, path,
clusterSummary, mgtmResources, logger)
clusterSummary, mgmtResources, logger)
}

if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions controllers/template_instantiation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type currentClusterObjects struct {
Cluster map[string]interface{}
KubeadmControlPlane map[string]interface{}
InfrastructureProvider map[string]interface{}
MgtmResources map[string]map[string]interface{}
MgmtResources map[string]map[string]interface{}
}

func fetchResource(ctx context.Context, config *rest.Config, namespace, name, apiVersion, kind string,
Expand Down Expand Up @@ -154,19 +154,19 @@ func fecthClusterObjects(ctx context.Context, config *rest.Config, c client.Clie

func instantiateTemplateValues(ctx context.Context, config *rest.Config, c client.Client,
clusterType libsveltosv1alpha1.ClusterType, clusterNamespace, clusterName, requestorName, values string,
mgtmResources map[string]*unstructured.Unstructured, logger logr.Logger) (string, error) {
mgmtResources map[string]*unstructured.Unstructured, logger logr.Logger) (string, error) {

objects, err := fecthClusterObjects(ctx, config, c, clusterNamespace, clusterName, clusterType, logger)
if err != nil {
return "", err
}

if mgtmResources != nil {
objects.MgtmResources = make(map[string]map[string]interface{})
for k := range mgtmResources {
if mgmtResources != nil {
objects.MgmtResources = make(map[string]map[string]interface{})
for k := range mgmtResources {
logger.V(logs.LogDebug).Info(fmt.Sprintf("using mgmt resource %s %s/%s with identifier %s",
mgtmResources[k].GetKind(), mgtmResources[k].GetNamespace(), mgtmResources[k].GetName(), k))
objects.MgtmResources[k] = mgtmResources[k].UnstructuredContent()
mgmtResources[k].GetKind(), mgmtResources[k].GetNamespace(), mgmtResources[k].GetName(), k))
objects.MgmtResources[k] = mgmtResources[k].UnstructuredContent()
}
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/template_instantiation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var _ = Describe("Template instantiation", func() {
Expect(testEnv.Client.Create(context.TODO(), secret)).To(Succeed())
Expect(waitForObject(ctx, testEnv.Client, secret)).To(Succeed())

values := `{{ $pwd := printf "%s" (index .MgtmResources "Secret").data.password }}
values := `{{ $pwd := printf "%s" (index .MgmtResources "Secret").data.password }}
valuesTemplate: |
password: "{{b64dec $pwd}}"`

Expand Down
6 changes: 3 additions & 3 deletions examples/autoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ data:
kind: Secret
metadata:
name: autoscaler
namespace: {{ (index .MgtmResources "AutoscalerSecret").metadata.namespace }}
namespace: {{ (index .MgmtResources "AutoscalerSecret").metadata.namespace }}
data:
token: {{ (index .MgtmResources "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(index .MgtmResources "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
token: {{ (index .MgmtResources "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(index .MgmtResources "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}
6 changes: 3 additions & 3 deletions test/fv/autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ type: kubernetes.io/service-account-token`
kind: Secret
metadata:
name: autoscaler
namespace: {{ (index .MgtmResources "AutoscalerSecret").metadata.namespace }}
namespace: {{ (index .MgmtResources "AutoscalerSecret").metadata.namespace }}
data:
token: {{ (index .MgtmResources "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(index .MgtmResources "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}`
token: {{ (index .MgmtResources "AutoscalerSecret").data.token }}
ca.crt: {{ $data:=(index .MgmtResources "AutoscalerSecret").data }} {{ (index $data "ca.crt") }}`
)

var _ = Describe("Feature", func() {
Expand Down