From fb637f7890b1410148a10fa4db84a9baf1aa63e0 Mon Sep 17 00:00:00 2001 From: Leo Ryu Date: Tue, 28 Jun 2022 19:44:42 +0800 Subject: [PATCH] feat(platform): support registry to cluster net (#2005) --- api/platform/types.go | 5 +++++ api/platform/v1/types.go | 5 +++++ .../provider/baremetal/cluster/create.go | 21 +++++++++++++++++++ .../provider/baremetal/cluster/provider.go | 2 ++ pkg/platform/types/v1/types.go | 5 ----- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/api/platform/types.go b/api/platform/types.go index f6cd18b56..666dd785f 100644 --- a/api/platform/types.go +++ b/api/platform/types.go @@ -100,6 +100,11 @@ const ( // SOCKS5 ProxyType = "SOCKS5" ) +const ( + // RegistrationCommandAnno contains base64 registration command of cluster net + RegistrationCommandAnno = "tkestack.io/registration-command" +) + // KubeVendorType describe the kubernetes provider of the cluster // ref https://github.com/open-cluster-management/multicloud-operators-foundation/blob/e94b719de6d5f3541e948dd70ad8f1ff748aa452/pkg/apis/internal.open-cluster-management.io/v1beta1/clusterinfo_types.go#L137 type KubeVendorType string diff --git a/api/platform/v1/types.go b/api/platform/v1/types.go index 65076c6d8..604270b06 100644 --- a/api/platform/v1/types.go +++ b/api/platform/v1/types.go @@ -111,6 +111,11 @@ const ( // SOCKS5 ProxyType = "SOCKS5" ) +const ( + // RegistrationCommandAnno contains base64 registration command of cluster net + RegistrationCommandAnno = "tkestack.io/registration-command" +) + // KubeVendorType describe the kubernetes provider of the cluster // ref https://github.com/open-cluster-management/multicloud-operators-foundation/blob/e94b719de6d5f3541e948dd70ad8f1ff748aa452/pkg/apis/internal.open-cluster-management.io/v1beta1/clusterinfo_types.go#L137 type KubeVendorType string diff --git a/pkg/platform/provider/baremetal/cluster/create.go b/pkg/platform/provider/baremetal/cluster/create.go index 2bce94d10..54cf4ca13 100644 --- a/pkg/platform/provider/baremetal/cluster/create.go +++ b/pkg/platform/provider/baremetal/cluster/create.go @@ -21,6 +21,7 @@ package cluster import ( "bytes" "context" + "encoding/base64" "encoding/hex" "fmt" "io/ioutil" @@ -1534,3 +1535,23 @@ func (p *Provider) EnsureInitAPIServerHost(ctx context.Context, c *v1.Cluster) e func (p *Provider) EnsureModifyAPIServerHost(ctx context.Context, c *v1.Cluster) error { return p.setAPIServerHost(ctx, c, "127.0.0.1") } + +func (p *Provider) EnsureClusternetRegistration(ctx context.Context, c *v1.Cluster) error { + if c.Annotations[platformv1.RegistrationCommandAnno] == "" { + log.FromContext(ctx).Info("registration command is empty, skip EnsureClusternetRegistration") + return nil + } + cmd, err := base64.StdEncoding.DecodeString(c.Annotations[platformv1.RegistrationCommandAnno]) + if err != nil { + return fmt.Errorf("decode registration command failed: %v", err) + } + machineSSH, err := c.Spec.Machines[0].SSH() + if err != nil { + return err + } + _, stderr, exit, err := machineSSH.Exec(string(cmd)) + if err != nil { + return fmt.Errorf("exec %q failed:exit %d:stderr %s:error %s", cmd, exit, stderr, err) + } + return nil +} diff --git a/pkg/platform/provider/baremetal/cluster/provider.go b/pkg/platform/provider/baremetal/cluster/provider.go index 2aa639dbd..a97aac256 100644 --- a/pkg/platform/provider/baremetal/cluster/provider.go +++ b/pkg/platform/provider/baremetal/cluster/provider.go @@ -115,6 +115,8 @@ func NewProvider() (*Provider, error) { p.EnsureJoinPhaseControlPlaneJoinETCD, p.EnsureJoinPhaseControlPlaneJoinUpdateStatus, + p.EnsureClusternetRegistration, + p.EnsureGalaxy, p.EnsureCilium, diff --git a/pkg/platform/types/v1/types.go b/pkg/platform/types/v1/types.go index efd3d6c46..358642375 100644 --- a/pkg/platform/types/v1/types.go +++ b/pkg/platform/types/v1/types.go @@ -106,12 +106,7 @@ func (c *Cluster) RESTConfigForBootstrap() (*rest.Config, error) { if err != nil { return nil, err } - host, err := c.HostForBootstrap() - if err != nil { - return nil, err - } configCopy := *c.restConfig - configCopy.Host = host return &configCopy, nil }