in cmd/generate.go [141:209]
func (gc *generateCmd) loadAPIModel() error {
var caCertificateBytes []byte
var caKeyBytes []byte
var err error
apiloader := &api.Apiloader{
Translator: &i18n.Translator{
Locale: gc.locale,
},
}
gc.containerService, gc.apiVersion, err = apiloader.LoadContainerServiceFromFile(gc.apimodelPath, false, false, nil)
if err != nil {
return errors.Wrap(err, "error parsing the api model")
}
if gc.containerService.Properties.MasterProfile == nil {
return errors.New("MasterProfile can't be nil")
}
if gc.outputDirectory == "" {
gc.outputDirectory = path.Join("_output", gc.containerService.Properties.MasterProfile.DNSPrefix)
}
// consume gc.caCertificatePath and gc.caPrivateKeyPath
if (gc.caCertificatePath != "" && gc.caPrivateKeyPath == "") || (gc.caCertificatePath == "" && gc.caPrivateKeyPath != "") {
return errors.New("--ca-certificate-path and --ca-private-key-path must be specified together")
}
if gc.caCertificatePath != "" {
if caCertificateBytes, err = os.ReadFile(gc.caCertificatePath); err != nil {
return errors.Wrap(err, "failed to read CA certificate file")
}
if caKeyBytes, err = os.ReadFile(gc.caPrivateKeyPath); err != nil {
return errors.Wrap(err, "failed to read CA private key file")
}
prop := gc.containerService.Properties
if prop.CertificateProfile == nil {
prop.CertificateProfile = &api.CertificateProfile{}
}
prop.CertificateProfile.CaCertificate = string(caCertificateBytes)
prop.CertificateProfile.CaPrivateKey = string(caKeyBytes)
}
if gc.containerService.Properties.IsAzureStackCloud() {
if gc.containerService.Properties.MasterProfile.Distro == api.AKSUbuntu1604 {
log.Errorln("Distro 'aks-ubuntu-16.04' is not longer supported on Azure Stack Hub, use 'aks-ubuntu-20.04' instead")
return errors.New("invalid master profile distro 'aks-ubuntu-16.04'")
} else if gc.containerService.Properties.MasterProfile.Distro == api.AKSUbuntu1804 {
log.Errorln("Distro 'aks-ubuntu-18.04' is not longer supported on Azure Stack Hub, use 'aks-ubuntu-20.04' instead")
return errors.New("invalid master profile distro 'aks-ubuntu-18.04'")
}
for _, app := range gc.containerService.Properties.AgentPoolProfiles {
if app.Distro == api.AKSUbuntu1604 {
log.Errorln("Distro 'aks-ubuntu-16.04' is not longer supported on Azure Stack Hub, use 'aks-ubuntu-20.04' instead")
return errors.New("invalid agent pool profile distro 'aks-ubuntu-16.04'")
} else if app.Distro == api.AKSUbuntu1804 {
log.Errorln("Distro 'aks-ubuntu-18.04' is not longer supported on Azure Stack Hub, use 'aks-ubuntu-20.04' instead")
return errors.New("invalid agent pool profile distro 'aks-ubuntu-18.04'")
}
}
}
if err = gc.autofillApimodel(); err != nil {
return err
}
return nil
}