Skip to content

Commit

Permalink
feat(platform): support registry to cluster net (#2005)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Ryu committed Jun 28, 2022
1 parent 7a6737b commit fb637f7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions pkg/platform/provider/baremetal/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package cluster
import (
"bytes"
"context"
"encoding/base64"
"encoding/hex"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions pkg/platform/provider/baremetal/cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func NewProvider() (*Provider, error) {
p.EnsureJoinPhaseControlPlaneJoinETCD,
p.EnsureJoinPhaseControlPlaneJoinUpdateStatus,

p.EnsureClusternetRegistration,

p.EnsureGalaxy,
p.EnsureCilium,

Expand Down
5 changes: 0 additions & 5 deletions pkg/platform/types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fb637f7

Please sign in to comment.