Skip to content

Commit

Permalink
Merge pull request #414 from darkmuggle/pr/optioanl
Browse files Browse the repository at this point in the history
Bare Control Planes: allow for creating control planes without a config
  • Loading branch information
branden committed Jan 30, 2024
2 parents 1f3a162 + adbd584 commit 38a5d27
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 37 deletions.
9 changes: 5 additions & 4 deletions cmd/up/controlplane/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type ctpCreator interface {
type createCmd struct {
Name string `arg:"" required:"" help:"Name of control plane."`

ConfigurationName string `help:"The name of the Configuration. This property is required for cloud control planes."`
Description string `short:"d" help:"Description for control plane."`
ConfigurationName *string `help:"The optional name of the Configuration."`
Description string `short:"d" help:"Description for control plane."`

SecretName string `help:"The name of the control plane's secret. Defaults to 'kubeconfig-{control plane name}'. Only applicable for Space control planes."`
SecretNamespace string `default:"default" help:"The name of namespace for the control plane's secret. Only applicable for Space control planes."`
Expand Down Expand Up @@ -81,8 +81,9 @@ func (c *createCmd) Run(ctx context.Context, p pterm.TextPrinter, upCtx *upbound
ctx,
c.Name,
controlplane.Options{
SecretName: c.SecretName,
SecretNamespace: c.SecretNamespace,
SecretName: c.SecretName,
SecretNamespace: c.SecretNamespace,
ConfigurationName: c.ConfigurationName,
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/sourcegraph/jsonrpc2 v0.2.0
github.com/spf13/afero v1.10.0
github.com/spf13/cobra v1.7.0
github.com/upbound/up-sdk-go v0.1.1-0.20230405182644-366f20e6aa5f
github.com/upbound/up-sdk-go v0.1.1-0.20240122203953-2d00664aab8e
github.com/willabides/kongplete v0.3.0
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/sync v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oW
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/upbound/up-sdk-go v0.1.1-0.20230405182644-366f20e6aa5f h1:k/beHtZrHDM881FwkwwXycRZSnxwjAS3Bd9Mq/UvwUs=
github.com/upbound/up-sdk-go v0.1.1-0.20230405182644-366f20e6aa5f/go.mod h1:IDIbYDb9fbedtxCc2CrdGcVRol6la7z2gkKh0VYWVGk=
github.com/upbound/up-sdk-go v0.1.1-0.20240122203953-2d00664aab8e h1:aNzUuv4ZKH2OT3Qv6dpZxkMPDOfl/6MoS79T/zUzako=
github.com/upbound/up-sdk-go v0.1.1-0.20240122203953-2d00664aab8e/go.mod h1:IDIbYDb9fbedtxCc2CrdGcVRol6la7z2gkKh0VYWVGk=
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck=
github.com/vbatts/tar-split v0.11.3/go.mod h1:9QlHN18E+fEH7RdG+QAJJcuya3rqT7eXSTY7wGrAokY=
Expand Down
38 changes: 14 additions & 24 deletions internal/controlplane/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,20 @@ func (c *Client) List(ctx context.Context) ([]*controlplane.Response, error) {

// Create a new ControlPlane with the given name and the supplied Options.
func (c *Client) Create(ctx context.Context, name string, opts controlplane.Options) (*controlplane.Response, error) {
// Get the UUID from the Configuration name, if it exists.
cfg, err := c.cfg.Get(ctx, c.account, opts.ConfigurationName)
if err != nil {
return nil, err
params := &controlplanes.ControlPlaneCreateParameters{
Name: name,
Description: opts.Description,
}
if opts.ConfigurationName != nil {
// Get the UUID from the Configuration name, if it exists.
cfg, err := c.cfg.Get(ctx, c.account, *opts.ConfigurationName)
if err != nil {
return nil, err
}
params.ConfigurationID = &cfg.ID
}

resp, err := c.ctp.Create(ctx, c.account, &controlplanes.ControlPlaneCreateParameters{
Name: name,
Description: opts.Description,
ConfigurationID: cfg.ID,
})
resp, err := c.ctp.Create(ctx, c.account, params)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -158,16 +161,10 @@ func (c *Client) GetKubeConfig(ctx context.Context, name string) (*api.Config, e
}

func convert(ctp *controlplanes.ControlPlaneResponse) *controlplane.Response {

var cfgName string
var cfgStatus string
// All Upbound managed control planes in an account should be associated to a configuration.
// However, we should still list all control planes and indicate where this isn't the case.
if ctp.ControlPlane.Configuration.Name != nil && ctp.ControlPlane.Configuration != EmptyControlPlaneConfiguration() {
cfgName, cfgStatus := notAvailable, notAvailable
if ctp.ControlPlane.Configuration != nil {
cfgName = *ctp.ControlPlane.Configuration.Name
cfgStatus = string(ctp.ControlPlane.Configuration.Status)
} else {
cfgName, cfgStatus = notAvailable, notAvailable
}

return &controlplane.Response{
Expand All @@ -178,10 +175,3 @@ func convert(ctp *controlplanes.ControlPlaneResponse) *controlplane.Response {
CfgStatus: cfgStatus,
}
}

// EmptyControlPlaneConfiguration returns an empty ControlPlaneConfiguration with default values.
func EmptyControlPlaneConfiguration() controlplanes.ControlPlaneConfiguration {
configuration := controlplanes.ControlPlaneConfiguration{}
configuration.Status = controlplanes.ConfigurationInstallationQueued
return configuration
}
9 changes: 4 additions & 5 deletions internal/controlplane/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
ctp1 = controlplanes.ControlPlane{
Name: "ctp1",
ID: uuid.MustParse("00000000-0000-0000-0000-000000000000"),
Configuration: controlplanes.ControlPlaneConfiguration{
Configuration: &controlplanes.ControlPlaneConfiguration{
Name: pointer.String("cfg1"),
Status: controlplanes.ConfigurationReady,
},
Expand All @@ -53,7 +53,7 @@ var (
ctp2 = controlplanes.ControlPlane{
Name: "ctp2",
ID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
Configuration: controlplanes.ControlPlaneConfiguration{
Configuration: &controlplanes.ControlPlaneConfiguration{
Name: pointer.String("cfg1"),
Status: controlplanes.ConfigurationReady,
},
Expand Down Expand Up @@ -337,9 +337,8 @@ func TestConvert(t *testing.T) {
args: args{
ctp: &controlplanes.ControlPlaneResponse{
ControlPlane: controlplanes.ControlPlane{
Name: "ctp1",
ID: uuid.MustParse("00000000-0000-0000-0000-000000000000"),
Configuration: controlplanes.ControlPlaneConfiguration{},
Name: "ctp1",
ID: uuid.MustParse("00000000-0000-0000-0000-000000000000"),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/controlplane/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ type Options struct {

Description string

ConfigurationName string
ConfigurationName *string
}

0 comments on commit 38a5d27

Please sign in to comment.