Skip to content

Commit

Permalink
feat(platform): support create superedge edge cluster (#1994)
Browse files Browse the repository at this point in the history
Signed-off-by: 00pf00 <[email protected]>
  • Loading branch information
Leo Ryu authored and 00pf00 committed Jul 12, 2022
1 parent c2b9af7 commit c260f64
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 28 deletions.
32 changes: 16 additions & 16 deletions pkg/platform/provider/baremetal/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ func (p *Provider) EnsurePreflight(ctx context.Context, c *v1.Cluster) error {
}

func (p *Provider) EnsureRegistryHosts(ctx context.Context, c *v1.Cluster) error {
if !p.config.Registry.NeedSetHosts() {
if !p.Config.Registry.NeedSetHosts() {
return nil
}
machines := map[bool][]platformv1.ClusterMachine{
true: c.Spec.ScalingMachines,
false: c.Spec.Machines}[len(c.Spec.ScalingMachines) > 0]
domains := []string{
p.config.Registry.Domain,
p.Config.Registry.Domain,
}
if c.Spec.TenantID != "" {
domains = append(domains, c.Spec.TenantID+"."+p.config.Registry.Domain)
domains = append(domains, c.Spec.TenantID+"."+p.Config.Registry.Domain)
}
for _, machine := range machines {
machineSSH, err := machine.SSH()
Expand All @@ -181,7 +181,7 @@ func (p *Provider) EnsureRegistryHosts(ctx context.Context, c *v1.Cluster) error

for _, one := range domains {
remoteHosts := hosts.RemoteHosts{Host: one, SSH: machineSSH}
err := remoteHosts.Set(p.config.Registry.IP)
err := remoteHosts.Set(p.Config.Registry.IP)
if err != nil {
return errors.Wrap(err, machine.IP)
}
Expand Down Expand Up @@ -499,9 +499,9 @@ func (p *Provider) EnsureContainerRuntime(ctx context.Context, c *v1.Cluster) er
}

func (p *Provider) EnsureContainerd(ctx context.Context, c *v1.Cluster) error {
insecureRegistries := []string{p.config.Registry.Domain}
if p.config.Registry.NeedSetHosts() && c.Spec.TenantID != "" {
insecureRegistries = append(insecureRegistries, c.Spec.TenantID+"."+p.config.Registry.Domain)
insecureRegistries := []string{p.Config.Registry.Domain}
if p.Config.Registry.NeedSetHosts() && c.Spec.TenantID != "" {
insecureRegistries = append(insecureRegistries, c.Spec.TenantID+"."+p.Config.Registry.Domain)
}
option := &containerd.Option{
InsecureRegistries: insecureRegistries,
Expand All @@ -527,15 +527,15 @@ func (p *Provider) EnsureDocker(ctx context.Context, c *v1.Cluster) error {
machines := map[bool][]platformv1.ClusterMachine{
true: c.Spec.ScalingMachines,
false: c.Spec.Machines}[len(c.Spec.ScalingMachines) > 0]
insecureRegistries := fmt.Sprintf(`"%s"`, p.config.Registry.Domain)
if p.config.Registry.NeedSetHosts() && c.Spec.TenantID != "" {
insecureRegistries = fmt.Sprintf(`%s,"%s"`, insecureRegistries, c.Spec.TenantID+"."+p.config.Registry.Domain)
insecureRegistries := fmt.Sprintf(`"%s"`, p.Config.Registry.Domain)
if p.Config.Registry.NeedSetHosts() && c.Spec.TenantID != "" {
insecureRegistries = fmt.Sprintf(`%s,"%s"`, insecureRegistries, c.Spec.TenantID+"."+p.Config.Registry.Domain)
}
extraArgs := c.Spec.DockerExtraArgs
utilruntime.Must(mergo.Merge(&extraArgs, p.config.Docker.ExtraArgs))
utilruntime.Must(mergo.Merge(&extraArgs, p.Config.Docker.ExtraArgs))
option := &docker.Option{
InsecureRegistries: insecureRegistries,
RegistryDomain: p.config.Registry.Domain,
RegistryDomain: p.Config.Registry.Domain,
ExtraArgs: extraArgs,
}
for _, machine := range machines {
Expand All @@ -558,7 +558,7 @@ func (p *Provider) EnsureKubernetesImages(ctx context.Context, c *v1.Cluster) er
machines := map[bool][]platformv1.ClusterMachine{
true: c.Spec.ScalingMachines,
false: c.Spec.Machines}[len(c.Spec.ScalingMachines) > 0]
option := &image.Option{Version: c.Spec.Version, RegistryDomain: p.config.Registry.Domain, KubeImages: images.KubecomponetNames}
option := &image.Option{Version: c.Spec.Version, RegistryDomain: p.Config.Registry.Domain, KubeImages: images.KubecomponetNames}
for _, machine := range machines {
machineSSH, err := machine.SSH()
if err != nil {
Expand Down Expand Up @@ -724,7 +724,7 @@ func (p *Provider) EnsureAuthzWebhook(ctx context.Context, c *v1.Cluster) error
if isGlobalCluster {
authzEndpoint, _ = c.AuthzWebhookBuiltinEndpoint()
} else {
authzEndpoint = p.config.AuthzWebhook.Endpoint
authzEndpoint = p.Config.AuthzWebhook.Endpoint
}
}
option := authzwebhook.Option{
Expand Down Expand Up @@ -758,7 +758,7 @@ func (p *Provider) EnsurePrepareForControlplane(ctx context.Context, c *v1.Clust
return errors.Wrap(err, "parse schedulerPolicyConfig error")
}
auditWebhookConfig, err := template.ParseString(auditWebhookConfig, map[string]interface{}{
"AuditBackendAddress": p.config.Audit.Address,
"AuditBackendAddress": p.Config.Audit.Address,
"ClusterName": c.Name,
})
if err != nil {
Expand Down Expand Up @@ -788,7 +788,7 @@ func (p *Provider) EnsurePrepareForControlplane(ctx context.Context, c *v1.Clust
}
}

if p.config.AuditEnabled() {
if p.Config.AuditEnabled() {
if len(auditPolicyData) != 0 {
err = machineSSH.WriteFile(bytes.NewReader(auditPolicyData), constants.KubernetesAuditPolicyConfigFile)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/platform/provider/baremetal/cluster/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (p *Provider) getClusterConfiguration(c *v1.Cluster) *kubeadmv1beta2.Cluste
DNS: kubeadmv1beta2.DNS{
Type: kubeadmv1beta2.CoreDNS,
},
ImageRepository: p.config.Registry.Prefix,
ImageRepository: p.Config.Registry.Prefix,
ClusterName: c.Name,
FeatureGates: map[string]bool{
"IPv6DualStack": c.Cluster.Spec.Features.IPv6DualStack},
Expand Down Expand Up @@ -246,7 +246,7 @@ func (p *Provider) getAPIServerExtraArgs(c *v1.Cluster) map[string]string {
args := map[string]string{
"token-auth-file": constants.TokenFile,
}
if p.config.AuditEnabled() {
if p.Config.AuditEnabled() {
args["audit-policy-file"] = constants.KubernetesAuditPolicyConfigFile
args["audit-webhook-config-file"] = constants.KubernetesAuditWebhookConfigFile
}
Expand All @@ -259,7 +259,7 @@ func (p *Provider) getAPIServerExtraArgs(c *v1.Cluster) map[string]string {
}

utilruntime.Must(mergo.Merge(&args, c.Spec.APIServerExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.config.APIServer.ExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.Config.APIServer.ExtraArgs))

return args
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func (p *Provider) getControllerManagerExtraArgs(c *v1.Cluster) map[string]strin
}

utilruntime.Must(mergo.Merge(&args, c.Spec.ControllerManagerExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.config.ControllerManager.ExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.Config.ControllerManager.ExtraArgs))

return args
}
Expand All @@ -303,7 +303,7 @@ func (p *Provider) getSchedulerExtraArgs(c *v1.Cluster) map[string]string {
}

utilruntime.Must(mergo.Merge(&args, c.Spec.SchedulerExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.config.Scheduler.ExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.Config.Scheduler.ExtraArgs))

return args
}
Expand All @@ -314,7 +314,7 @@ func (p *Provider) getKubeletExtraArgs(c *v1.Cluster) map[string]string {
}

utilruntime.Must(mergo.Merge(&args, c.Spec.KubeletExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.config.Kubelet.ExtraArgs))
utilruntime.Must(mergo.Merge(&args, p.Config.Kubelet.ExtraArgs))

return args
}
12 changes: 6 additions & 6 deletions pkg/platform/provider/baremetal/cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func RegisterProvider() {
type Provider struct {
*clusterprovider.DelegateProvider

config *config.Config
Config *config.Config
}

var _ clusterprovider.Provider = &Provider{}
Expand Down Expand Up @@ -164,7 +164,7 @@ func NewProvider() (*Provider, error) {
if err != nil {
return nil, err
}
p.config = cfg
p.Config = cfg

containerregistry.Init(cfg.Registry.Domain, cfg.Registry.Namespace)

Expand Down Expand Up @@ -215,14 +215,14 @@ func (p *Provider) PreCreate(cluster *types.Cluster) error {
}
}

if p.config.AuditEnabled() {
if p.Config.AuditEnabled() {
if !cluster.AuthzWebhookEnabled() {
cluster.Spec.Features.AuthzWebhookAddr = &platform.AuthzWebhookAddr{Builtin: &platform.
BuiltinAuthzWebhookAddr{}}
}
}

if p.config.BusinessEnabled() {
if p.Config.BusinessEnabled() {
if !cluster.AuthzWebhookEnabled() {
cluster.Spec.Features.AuthzWebhookAddr = &platform.AuthzWebhookAddr{Builtin: &platform.
BuiltinAuthzWebhookAddr{}}
Expand All @@ -244,8 +244,8 @@ func (p *Provider) PreCreate(cluster *types.Cluster) error {
if !cluster.Spec.Features.EnableMetricsServer {
cluster.Spec.Features.SkipConditions = append(cluster.Spec.Features.SkipConditions, "EnsureMetricsServer")
}
if p.config.Feature.SkipConditions != nil {
cluster.Spec.Features.SkipConditions = append(cluster.Spec.Features.SkipConditions, p.config.Feature.SkipConditions...)
if p.Config.Feature.SkipConditions != nil {
cluster.Spec.Features.SkipConditions = append(cluster.Spec.Features.SkipConditions, p.Config.Feature.SkipConditions...)
}

if cluster.Spec.Etcd == nil {
Expand Down
Loading

0 comments on commit c260f64

Please sign in to comment.