Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
persist template
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis committed Dec 2, 2020
1 parent 7414d4c commit 7b71edf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/operations/kubernetesupgrade/upgradecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ package kubernetesupgrade

import (
"context"
"encoding/json"
"fmt"
"math/rand"
"path"
"strings"
"time"

"github.com/Azure/aks-engine/pkg/api"
"github.com/Azure/aks-engine/pkg/api/common"
"github.com/Azure/aks-engine/pkg/armhelpers"
"github.com/Azure/aks-engine/pkg/armhelpers/utils"
"github.com/Azure/aks-engine/pkg/engine"
"github.com/Azure/aks-engine/pkg/engine/transform"
"github.com/Azure/aks-engine/pkg/i18n"
"github.com/Azure/aks-engine/pkg/kubernetes"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
Expand Down Expand Up @@ -457,3 +461,29 @@ func (uc *UpgradeCluster) addVMToFinishedSets(vm compute.VirtualMachine, current
}
}
}

// WriteTemplate writes upgrade template to a folder
func WriteTemplate(
translator *i18n.Translator,
upgradeContainerService *api.ContainerService,
templateMap map[string]interface{}, parametersMap map[string]interface{},
filename string) {
updatedTemplateJSON, _ := json.Marshal(templateMap)
parametersJSON, _ := json.Marshal(parametersMap)

templateapp, err := transform.PrettyPrintArmTemplate(string(updatedTemplateJSON))
if err != nil {
logrus.Fatalf("error pretty printing template: %s \n", err.Error())
}
parametersapp, e := transform.PrettyPrintJSON(string(parametersJSON))
if e != nil {
logrus.Fatalf("error pretty printing template parameters: %s \n", e.Error())
}
outputDirectory := path.Join("_output", upgradeContainerService.Properties.MasterProfile.DNSPrefix, filename)
writer := &engine.ArtifactWriter{
Translator: translator,
}
if err := writer.WriteTLSArtifacts(upgradeContainerService, "vlabs", templateapp, parametersapp, outputDirectory, false, false); err != nil {
logrus.Fatalf("error writing artifacts: %s\n", err.Error())
}
}
2 changes: 2 additions & 0 deletions pkg/operations/kubernetesupgrade/upgrademasternode.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func (kmn *UpgradeMasterNode) CreateNode(ctx context.Context, poolName string, m
deploymentSuffix := random.Int31()
deploymentName := fmt.Sprintf("master-%s-%d", time.Now().Format("06-01-02T15.04.05"), deploymentSuffix)

WriteTemplate(kmn.Translator, kmn.UpgradeContainerService, kmn.TemplateMap, kmn.ParametersMap, deploymentName)

_, err := kmn.Client.DeployTemplate(
ctx,
kmn.ResourceGroup,
Expand Down

0 comments on commit 7b71edf

Please sign in to comment.