Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACM-6435: add pausedUntil create cluster option in CLI #2965

Merged
merged 7 commits into from Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/fixtures/example.go
Expand Up @@ -76,6 +76,7 @@ type ExampleOptions struct {
EtcdStorageClass string
ExternalDNSDomain string
Arch string
PausedUntil string
AWS *ExampleAWSOptions
None *ExampleNoneOptions
Agent *ExampleAgentOptions
Expand Down Expand Up @@ -460,6 +461,10 @@ func (o ExampleOptions) Resources() *ExampleResources {
},
}

if len(o.PausedUntil) > 0 {
cluster.Spec.PausedUntil = &o.PausedUntil
}

if o.BaseDomainPrefix == "none" {
// set empty prefix explicitly
cluster.Spec.DNS.BaseDomainPrefix = pointer.String("")
Expand Down Expand Up @@ -621,6 +626,12 @@ func (o ExampleOptions) Resources() *ExampleResources {
panic("Unsupported platform")
}

if len(o.PausedUntil) > 0 {
for _, nodePool := range nodePools {
nodePool.Spec.PausedUntil = &o.PausedUntil
}
}

return &ExampleResources{
AdditionalTrustBundle: userCABundleCM,
Namespace: namespace,
Expand Down
1 change: 1 addition & 0 deletions cmd/cluster/cluster.go
Expand Up @@ -79,6 +79,7 @@ func NewCreateCommands() *cobra.Command {
cmd.PersistentFlags().DurationVar(&opts.Timeout, "timeout", opts.Timeout, "If the --wait flag is set, set the optional timeout to limit the waiting duration. The format is duration; e.g. 30s or 1h30m45s; 0 means no timeout; default = 0")
cmd.PersistentFlags().Var(&opts.NodeUpgradeType, "node-upgrade-type", "The NodePool upgrade strategy for how nodes should behave when upgraded. Supported options: Replace, InPlace")
cmd.PersistentFlags().StringVar(&opts.Arch, "arch", opts.Arch, "The default processor architecture for the NodePool (e.g. arm64, amd64)")
cmd.PersistentFlags().StringVar(&opts.PausedUntil, "pausedUntil", opts.PausedUntil, "If a date is provided in RFC3339 format, HostedCluster creation is paused until that date. If the boolean true is provided, HostedCluster creation is paused until the field is removed.")

cmd.AddCommand(aws.NewCreateCommand(opts))
cmd.AddCommand(none.NewCreateCommand(opts))
Expand Down
11 changes: 11 additions & 0 deletions cmd/cluster/core/create.go
Expand Up @@ -77,6 +77,7 @@ type CreateOptions struct {
SkipAPIBudgetVerification bool
CredentialSecretName string
NodeUpgradeType hyperv1.UpgradeType
PausedUntil string

// BeforeApply is called immediately before resources are applied to the
// server, giving the user an opportunity to inspect or mutate the resources.
Expand Down Expand Up @@ -256,6 +257,15 @@ func createCommonFixture(ctx context.Context, opts *CreateOptions) (*apifixtures

}

// validate pausedUntil value
// valid values are either "true" or RFC3339 format date
if len(opts.PausedUntil) > 0 && opts.PausedUntil != "true" {
_, err := time.Parse(time.RFC3339, opts.PausedUntil)
if err != nil {
return nil, fmt.Errorf("invalid pausedUntil value, should be \"true\" or a valid RFC3339 date format: %w", err)
}
}

return &apifixtures.ExampleOptions{
AdditionalTrustBundle: string(userCABundle),
ImageContentSources: imageContentSources,
Expand All @@ -280,6 +290,7 @@ func createCommonFixture(ctx context.Context, opts *CreateOptions) (*apifixtures
Arch: opts.Arch,
NodeSelector: opts.NodeSelector,
UpgradeType: opts.NodeUpgradeType,
PausedUntil: opts.PausedUntil,
}, nil
}

Expand Down
Expand Up @@ -248,19 +248,20 @@ func serviceFirstNodePortAvailable(svc *corev1.Service) bool {
// pauseHostedControlPlane will handle adding the pausedUntil field to the hostedControlPlane object if it exists.
// If it doesn't exist: it returns as there's no need to add it
func pauseHostedControlPlane(ctx context.Context, c client.Client, hcp *hyperv1.HostedControlPlane, pauseValue *string) error {
err := c.Get(ctx, client.ObjectKeyFromObject(hcp), hcp)
if err != nil {
if apierrors.IsNotFound(err) {
if hcp != nil {
rokej marked this conversation as resolved.
Show resolved Hide resolved
err := c.Get(ctx, client.ObjectKeyFromObject(hcp), hcp)
if err != nil {
if !apierrors.IsNotFound(err) {
return fmt.Errorf("failed to get hostedcontrolplane: %w", err)
}
return nil
} else {
return fmt.Errorf("failed to get hostedcontrolplane: %w", err)
}
}

if hcp.Spec.PausedUntil != pauseValue {
hcp.Spec.PausedUntil = pauseValue
if err := c.Update(ctx, hcp); err != nil {
return fmt.Errorf("failed to pause hostedcontrolplane: %w", err)
if hcp.Spec.PausedUntil != pauseValue {
hcp.Spec.PausedUntil = pauseValue
if err := c.Update(ctx, hcp); err != nil {
return fmt.Errorf("failed to pause hostedcontrolplane: %w", err)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions product-cli/cmd/cluster/cluster.go
rokej marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -33,6 +33,7 @@ func NewCreateCommands() *cobra.Command {
ServiceCIDR: "172.31.0.0/16",
Timeout: 0,
Wait: false,
PausedUntil: "",
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -67,6 +68,7 @@ func NewCreateCommands() *cobra.Command {
cmd.PersistentFlags().StringVar(&opts.SSHKeyFile, "ssh-key", opts.SSHKeyFile, "Filepath to an SSH key file.")
cmd.PersistentFlags().DurationVar(&opts.Timeout, "timeout", opts.Timeout, "If the --wait flag is set, set the optional timeout to limit the duration of the wait (Examples: 30s, 1h30m45s, etc.) 0 means no timeout.")
cmd.PersistentFlags().BoolVar(&opts.Wait, "wait", opts.Wait, "If true, the create command will block until the HostedCluster is up. Requires at least one NodePool with at least one node.")
cmd.PersistentFlags().StringVar(&opts.PausedUntil, "pausedUntil", opts.PausedUntil, "If a date is provided in RFC3339 format, HostedCluster creation is paused until that date. If the boolean true is provided, HostedCluster creation is paused until the field is removed.")

_ = cmd.MarkPersistentFlagRequired("pull-secret")

Expand Down