-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow for specifying namespace in infra providers
This PR adds the ability to the pkgs as well as to ./capi to specify a namespace for an infra provider. It also busts the bootstrap command into two subcommands, core and infra. This makes it easier to handle infra providers in a separate namespace. UX wise, it'll look like: ``` $ ./capi bootstrap core $ ./capi bootstrap infra --providers aws:v0.6.8 --target-ns my-ns --watching-ns my-test-ns ``` with the ns flags being optional of course. Signed-off-by: Spencer Smith <[email protected]>
- Loading branch information
Showing
10 changed files
with
317 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/talos-systems/capi-utils/pkg/capi" | ||
"github.com/talos-systems/capi-utils/pkg/capi/infrastructure" | ||
) | ||
|
||
var capiCoreCmd = &cobra.Command{ | ||
Use: "core", | ||
Short: "Install and patch core CAPI.", | ||
Long: ` | ||
This command installs everything for CAPI *but* infrastructure providers. | ||
It is assumed that these core components are global watchers and can handle | ||
reconciling CAPI resources across any namespace. | ||
`, | ||
Example: ` | ||
capi bootstrap core | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.Background() | ||
|
||
var err error | ||
|
||
manager, err = capi.NewManager(ctx, capi.Options{ | ||
ClusterctlConfigPath: options.ClusterctlConfigPath, | ||
CoreProvider: options.CoreProvider, | ||
BootstrapProviders: options.BootstrapProviders, | ||
InfrastructureProviders: []infrastructure.Provider{}, | ||
ControlPlaneProviders: options.ControlPlaneProviders, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return manager.Install(ctx) | ||
}, | ||
} | ||
|
||
func init() { | ||
bootstrapCmd.AddCommand(capiCoreCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/talos-systems/capi-utils/pkg/capi" | ||
"github.com/talos-systems/capi-utils/pkg/capi/infrastructure" | ||
"github.com/talos-systems/capi-utils/pkg/constants" | ||
) | ||
|
||
var ( | ||
targetNS string | ||
watchingNS string | ||
) | ||
|
||
var capiInfraCmd = &cobra.Command{ | ||
Use: "infra", | ||
Short: "Install and patch CAPI infra providers.", | ||
Long: ``, | ||
Example: ` | ||
## Specifying multiple infra providers | ||
capi bootstrap infra --providers aws,sidero | ||
## Specifying namespaces and version for infra provider | ||
capi bootstrap infra --providers aws:v0.6.8 --target-ns my-ns --watching-ns my-ns-to-watch | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.Background() | ||
|
||
providers := make([]infrastructure.Provider, len(options.InfrastructureProviders)) | ||
for i, name := range options.InfrastructureProviders { | ||
provider, err := infrastructure.NewProvider( | ||
name, | ||
infrastructure.WithProviderNS(targetNS), | ||
infrastructure.WithWatchingNS(watchingNS), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if opts, ok := setupOptions[provider.Name()]; ok { | ||
if err = provider.Configure(opts); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
providers[i] = provider | ||
} | ||
|
||
var err error | ||
|
||
manager, err = capi.NewManager(ctx, capi.Options{ | ||
ClusterctlConfigPath: options.ClusterctlConfigPath, | ||
CoreProvider: "", | ||
BootstrapProviders: []string{}, | ||
InfrastructureProviders: providers, | ||
ControlPlaneProviders: []string{}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return manager.Install(ctx) | ||
}, | ||
} | ||
|
||
func init() { | ||
bootstrapCmd.AddCommand(capiInfraCmd) | ||
capiInfraCmd.PersistentFlags().StringSliceVar(&options.InfrastructureProviders, "providers", []string{"aws"}, "Name(s) of infra provider(s) to init") | ||
capiInfraCmd.PersistentFlags().StringVar(&targetNS, "target-ns", "", "Namespace to install proivder in") | ||
capiInfraCmd.PersistentFlags().StringVar(&watchingNS, "watching-ns", "", "Namespace for provider to watch") | ||
|
||
// AWS provider flags | ||
opts := infrastructure.NewAWSSetupOptions() | ||
capiInfraCmd.PersistentFlags().StringVar(&opts.AWSCredentials, "aws-base64-encoded-credentials", awsOptions.b64EncodedCredentials, "AWS_B64ENCODED_CREDENTIALS") | ||
setupOptions[constants.AWSProviderName] = opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.