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

feat(kubeserver): deploy nginx ingress controller on self build aws cluster #340

Open
wants to merge 1 commit into
base: release/3.10
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions pkg/kubeserver/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/kubeserver/drivers/clusters/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion pkg/kubeserver/drivers/clusters/self_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubeserver/drivers/clusters/selfbuild/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (s *sAwsDriver) ChangeKubesprayVars(vars *kubespray.KubesprayVars) {
vars.NodelocalDNSImageRepo = ""
vars.DNSAutoscalerImageRepo = ""
vars.NginxImageRepo = ""
vars.IngressNginxControllerImageRepo = ""
vars.CorednsImageIsNamespaced = true

vars.KubeletDownloadUrl = ""
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pkg/kubeserver/drivers/clusters/selfbuild/base.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/kubeserver/drivers/clusters/selfbuild/interface.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
}
1 change: 1 addition & 0 deletions pkg/kubeserver/models/cluster_drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion pkg/kubeserver/models/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down