diff --git a/pkg/kubeserver/api/cluster.go b/pkg/kubeserver/api/cluster.go index e85440390..7cb726125 100644 --- a/pkg/kubeserver/api/cluster.go +++ b/pkg/kubeserver/api/cluster.go @@ -455,8 +455,13 @@ type ClusterAddonNetworkConfig struct { EnableNativeIPAlloc bool `json:"enable_native_ip_alloc"` } +type ClusterAddonIngressConfig struct { + EnableNginx *bool `json:"enable_nginx"` +} + type ClusterAddonsManifestConfig struct { Network ClusterAddonNetworkConfig `json:"network"` + Ingress ClusterAddonIngressConfig `json:"ingress"` } type ClusterKubesprayConfig struct { diff --git a/pkg/kubeserver/drivers/clusters/base.go b/pkg/kubeserver/drivers/clusters/base.go index 144c375ac..424b7ac06 100644 --- a/pkg/kubeserver/drivers/clusters/base.go +++ b/pkg/kubeserver/drivers/clusters/base.go @@ -51,6 +51,10 @@ func (d *SBaseDriver) ValidateCreateData(userCred mcclient.TokenCredential, owne return nil } +func (d *SBaseDriver) SetDefaultCreateData(ctx context.Context, cred mcclient.TokenCredential, id mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.ClusterCreateInput) error { + return nil +} + func (d *SBaseDriver) PreCheck(s *mcclient.ClientSession, data jsonutils.JSONObject) (*api.ClusterPreCheckResp, error) { return &api.ClusterPreCheckResp{ Pass: true, diff --git a/pkg/kubeserver/drivers/clusters/self_build.go b/pkg/kubeserver/drivers/clusters/self_build.go index 7bdb85e32..38f6984be 100644 --- a/pkg/kubeserver/drivers/clusters/self_build.go +++ b/pkg/kubeserver/drivers/clusters/self_build.go @@ -59,7 +59,7 @@ func registerSelfBuildClusterDriver(driver selfbuild.ISelfBuildDriver) { registerClusterDriver(newSelfBuildClusterDriver(driver)) } -func newSelfBuildClusterDriver(pDrv selfbuild.ISelfBuildDriver) models.IClusterDriver { +func newSelfBuildClusterDriver(pDrv selfbuild.ISelfBuildDriver) *selfBuildClusterDriver { drv := &selfBuildClusterDriver{ providerDriver: pDrv, } @@ -87,6 +87,10 @@ func (d *selfBuildClusterDriver) GetK8sVersions() []string { return d.providerDriver.GetK8sVersions() } +func (d *selfBuildClusterDriver) SetDefaultCreateData(ctx context.Context, cred mcclient.TokenCredential, id mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.ClusterCreateInput) error { + return d.providerDriver.SetDefaultCreateData(ctx, cred, id, query, input) +} + func (d *selfBuildClusterDriver) PreCheck(s *mcclient.ClientSession, data jsonutils.JSONObject) (*api.ClusterPreCheckResp, error) { mDrv, err := machines.GetYunionVMDriver().GetHypervisor(string(d.GetProvider())) if err != nil { @@ -206,6 +210,10 @@ func (c *selfBuildDriver) ValidateCreateData(ctx context.Context, userCred mccli return nil } +func (c *selfBuildDriver) SetDefaultCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.ClusterCreateInput) error { + return c.driver.SetDefaultCreateData(ctx, userCred, ownerId, query, input) +} + func getClusterMachineIndexs(cluster *models.SCluster, role string, count int) ([]int, error) { if count == 0 { return nil, nil diff --git a/pkg/kubeserver/drivers/clusters/selfbuild/aws.go b/pkg/kubeserver/drivers/clusters/selfbuild/aws.go index 084bdd480..acd594a80 100644 --- a/pkg/kubeserver/drivers/clusters/selfbuild/aws.go +++ b/pkg/kubeserver/drivers/clusters/selfbuild/aws.go @@ -38,7 +38,6 @@ func (s *sAwsDriver) ChangeKubesprayVars(vars *kubespray.KubesprayVars) { vars.NodelocalDNSImageRepo = "" vars.DNSAutoscalerImageRepo = "" vars.NginxImageRepo = "" - vars.IngressNginxControllerImageRepo = "" vars.CorednsImageIsNamespaced = true vars.KubeletDownloadUrl = "" @@ -56,6 +55,7 @@ func (s *sAwsDriver) ChangeKubesprayVars(vars *kubespray.KubesprayVars) { vars.DockerVersion = kubespray.DockerVersion_20_10 vars.DockerCliVersion = kubespray.DockerVersion_20_10 vars.KubeNetworkPlugin = kubespray.NetworkPluginCNI + vars.IngressNginxControllerImageRepo = "" vars.IngressNginxEnabled = false // vars.EnableNodelocalDNS = false // vars.OverrideSystemHostname = false diff --git a/pkg/kubeserver/drivers/clusters/selfbuild/base.go b/pkg/kubeserver/drivers/clusters/selfbuild/base.go index 67b0a76fd..95ad8df09 100644 --- a/pkg/kubeserver/drivers/clusters/selfbuild/base.go +++ b/pkg/kubeserver/drivers/clusters/selfbuild/base.go @@ -1,6 +1,11 @@ package selfbuild import ( + "context" + + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/kubecomps/pkg/kubeserver/api" "yunion.io/x/kubecomps/pkg/kubeserver/constants" "yunion.io/x/kubecomps/pkg/kubeserver/drivers/clusters/addons" @@ -45,6 +50,17 @@ func (s sBaseDriver) GetAddonsHelmCharts(cluster *models.SCluster, conf *api.Clu return nil, nil } +func (s sBaseDriver) SetDefaultCreateData(ctx context.Context, cred mcclient.TokenCredential, id mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.ClusterCreateInput) error { + if input.AddonsConfig == nil { + input.AddonsConfig = new(api.ClusterAddonsManifestConfig) + } + if input.AddonsConfig.Ingress.EnableNginx == nil { + defaultTrue := true + input.AddonsConfig.Ingress.EnableNginx = &defaultTrue + } + return nil +} + func (s sBaseDriver) GetAddonsManifest(cluster *models.SCluster, conf *api.ClusterAddonsManifestConfig) (string, error) { commonConf, err := GetCommonAddonsConfig(cluster) if err != nil { diff --git a/pkg/kubeserver/drivers/clusters/selfbuild/interface.go b/pkg/kubeserver/drivers/clusters/selfbuild/interface.go index 4ae656a5c..1dd339d53 100644 --- a/pkg/kubeserver/drivers/clusters/selfbuild/interface.go +++ b/pkg/kubeserver/drivers/clusters/selfbuild/interface.go @@ -1,6 +1,11 @@ package selfbuild import ( + "context" + + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/kubecomps/pkg/kubeserver/api" "yunion.io/x/kubecomps/pkg/kubeserver/drivers/clusters/kubespray" "yunion.io/x/kubecomps/pkg/kubeserver/models" @@ -15,4 +20,5 @@ type ISelfBuildDriver interface { GetAddonsHelmCharts(cluster *models.SCluster, conf *api.ClusterAddonsManifestConfig) ([]*models.ClusterHelmChartInstallOption, error) GetAddonsManifest(cluster *models.SCluster, conf *api.ClusterAddonsManifestConfig) (string, error) GetKubesprayHostname(info *client.ServerSSHLoginInfo) (string, error) + SetDefaultCreateData(ctx context.Context, cred mcclient.TokenCredential, id mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.ClusterCreateInput) error } diff --git a/pkg/kubeserver/models/cluster_drivers.go b/pkg/kubeserver/models/cluster_drivers.go index 0ba5a3447..490931f1a 100644 --- a/pkg/kubeserver/models/cluster_drivers.go +++ b/pkg/kubeserver/models/cluster_drivers.go @@ -56,6 +56,7 @@ type IClusterDriverMethods interface { NeedCreateMachines() bool ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *api.ClusterCreateInput) error + SetDefaultCreateData(ctx context.Context, cred mcclient.TokenCredential, id mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.ClusterCreateInput) error // RequestDeployMachines run ansible deploy machines as kubernetes nodes RequestDeployMachines(ctx context.Context, userCred mcclient.TokenCredential, cluster *SCluster, action api.ClusterDeployAction, machines []manager.IMachine, skipDownloads bool, task taskman.ITask) error GetKubesprayConfig(ctx context.Context, cluster *SCluster) (*api.ClusterKubesprayConfig, error) diff --git a/pkg/kubeserver/models/clusters.go b/pkg/kubeserver/models/clusters.go index 378feb5d6..d1f6f3e05 100644 --- a/pkg/kubeserver/models/clusters.go +++ b/pkg/kubeserver/models/clusters.go @@ -594,8 +594,13 @@ func (m *SClusterManager) ValidateCreateData(ctx context.Context, userCred mccli } } + drvHint := fmt.Sprintf("%s/%s/%s", input.Mode, input.Provider, input.ResourceType) if err := driver.ValidateCreateData(ctx, userCred, ownerId, query, input); err != nil { - return nil, err + return nil, errors.Wrapf(err, "driver %s ValidateCreateData", drvHint) + } + + if err := driver.SetDefaultCreateData(ctx, userCred, ownerId, query, input); err != nil { + return nil, errors.Wrapf(err, "driver %s SetDefaultCreateData", drvHint) } versions := driver.GetK8sVersions()