in cmd/scale.go [146:254]
func (sc *scaleCmd) load() error {
logger := log.New()
logger.Formatter = new(prefixed.TextFormatter)
sc.logger = log.NewEntry(log.New())
var err error
ctx, cancel := context.WithTimeout(context.Background(), armhelpers.DefaultARMOperationTimeout)
defer cancel()
sc.updateVMSSModel = true
if sc.apiModelPath == "" {
sc.apiModelPath = filepath.Join(sc.deploymentDirectory, apiModelFilename)
}
if _, err = os.Stat(sc.apiModelPath); os.IsNotExist(err) {
return errors.Errorf("specified api model does not exist (%s)", sc.apiModelPath)
}
apiloader := &api.Apiloader{
Translator: &i18n.Translator{
Locale: sc.locale,
},
}
sc.containerService, sc.apiVersion, err = apiloader.LoadContainerServiceFromFile(sc.apiModelPath, true, true, nil)
if err != nil {
return errors.Wrap(err, "error parsing the api model")
}
if sc.containerService.Properties.IsCustomCloudProfile() {
if err = writeCustomCloudProfile(sc.containerService); err != nil {
return errors.Wrap(err, "error writing custom cloud profile")
}
if err = sc.containerService.Properties.SetCustomCloudSpec(api.AzureCustomCloudSpecParams{IsUpgrade: false, IsScale: true}); err != nil {
return errors.Wrap(err, "error parsing the api model")
}
}
if err = sc.authArgs.validateAuthArgs(); err != nil {
return err
}
// Set env var if custom cloud profile is not nil
var env *api.Environment
if sc.containerService != nil &&
sc.containerService.Properties != nil &&
sc.containerService.Properties.CustomCloudProfile != nil {
env = sc.containerService.Properties.CustomCloudProfile.Environment
}
if sc.client, err = sc.authArgs.getClient(env); err != nil {
return errors.Wrap(err, "failed to get client")
}
_, err = sc.client.EnsureResourceGroup(ctx, sc.resourceGroupName, sc.location, nil)
if err != nil {
return err
}
if sc.containerService.Location == "" {
sc.containerService.Location = sc.location
} else if sc.containerService.Location != sc.location {
return errors.New("--location does not match api model location")
}
if sc.agentPoolToScale == "" {
agentPoolCount := len(sc.containerService.Properties.AgentPoolProfiles)
if agentPoolCount > 1 {
return errors.New("--node-pool is required if more than one agent pool is defined in the container service")
} else if agentPoolCount == 1 {
sc.agentPool = sc.containerService.Properties.AgentPoolProfiles[0]
sc.agentPoolIndex = 0
sc.agentPoolToScale = sc.containerService.Properties.AgentPoolProfiles[0].Name
} else {
return errors.New("No node pools found to scale")
}
} else {
agentPoolIndex := -1
for i, pool := range sc.containerService.Properties.AgentPoolProfiles {
if pool.Name == sc.agentPoolToScale {
agentPoolIndex = i
sc.agentPool = pool
sc.agentPoolIndex = i
}
}
if agentPoolIndex == -1 {
return errors.Errorf("node pool %s was not found in the deployed api model", sc.agentPoolToScale)
}
}
//allows to identify VMs in the resource group that belong to this cluster.
sc.nameSuffix = sc.containerService.Properties.GetClusterID()
log.Debugf("Cluster ID used in all agent pools: %s", sc.nameSuffix)
if sc.masterFQDN != "" {
if strings.HasPrefix(sc.masterFQDN, "https://") {
sc.apiserverURL = sc.masterFQDN
} else if strings.HasPrefix(sc.masterFQDN, "http://") {
return errors.New("apiserver URL cannot be insecure http://")
} else {
sc.apiserverURL = fmt.Sprintf("https://%s", sc.masterFQDN)
}
}
sc.kubeconfig, err = engine.GenerateKubeConfig(sc.containerService.Properties, sc.location)
if err != nil {
return errors.New("Unable to derive kubeconfig from api model")
}
return nil
}