Skip to content

Commit

Permalink
Merge branch 'master' into build-up-deprovision-step
Browse files Browse the repository at this point in the history
  • Loading branch information
jameszwang committed May 11, 2024
2 parents 2af311d + 5b0528a commit a6777cd
Show file tree
Hide file tree
Showing 71 changed files with 23,877 additions and 20,776 deletions.
3 changes: 2 additions & 1 deletion cmd/describe/breakglasscredential/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command, argv []string) error {
}

if breakGlassCredentialConfig.Status() == cmv1.BreakGlassCredentialStatusRevoked {
return fmt.Errorf("Break glass credential '%s' for cluster '%s' has been revoked.",
r.Reporter.Warnf("Break glass credential '%s' for cluster '%s' has been revoked.",
breakGlassCredentialId, clusterKey)
return nil
}

if output.HasFlag() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/describe/breakglasscredential/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ var _ = Describe("Break glass credential", func() {
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady))
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK,
test.FormatResource(revokedCredential)))
_, stderr, err := test.RunWithOutputCaptureAndArgv(runWithRuntime, testRuntime.RosaRuntime,
stdout, stderr, err := test.RunWithOutputCaptureAndArgv(runWithRuntime, testRuntime.RosaRuntime,
Cmd, &[]string{})
Expect(err.Error()).To(Equal("Break glass credential 'test-id' for cluster 'cluster1' has been revoked."))
Expect(stderr).To(Equal(""))
Expect(err).To(BeNil())
Expect(stderr).To(Equal("WARN: Break glass credential 'test-id' for cluster 'cluster1' has been revoked.\n"))
Expect(stdout).To(Equal(""))
})
})
})
4 changes: 2 additions & 2 deletions cmd/describe/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func DescribeMachinePoolRunner(userOptions DescribeMachinepoolUserOptions) rosa.
err := cmd.ParseFlags(argv)
userOptions.machinepool = cmd.Flag("machinepool").Value.String()
if err != nil {
return fmt.Errorf("unable to parse flags: %s", err)
return fmt.Errorf("Unable to parse flags: %s", err)
}
}
err := options.Bind(userOptions)
Expand All @@ -83,7 +83,7 @@ func DescribeMachinePoolRunner(userOptions DescribeMachinepoolUserOptions) rosa.
clusterKey := runtime.GetClusterKey()
cluster := runtime.FetchCluster()
if cluster.State() != cmv1.ClusterStateReady {
return fmt.Errorf("cluster '%s' is not yet ready", clusterKey)
return fmt.Errorf("Cluster '%s' is not yet ready", clusterKey)
}

service := machinepool.NewMachinePoolService()
Expand Down
3 changes: 3 additions & 0 deletions cmd/describe/machinepool/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Subnet:
Version: 4.12.24
Autorepair: No
Tuning configs:
Kubelet configs:
Additional security group IDs:
Node drain grace period: 1 minute
Message:
Expand All @@ -54,6 +55,7 @@ Subnet:
Version: 4.12.24
Autorepair: No
Tuning configs:
Kubelet configs:
Additional security group IDs:
Node drain grace period: 1 minute
Message:
Expand All @@ -74,6 +76,7 @@ Subnet:
Version: 4.12.24
Autorepair: No
Tuning configs:
Kubelet configs:
Additional security group IDs:
Node drain grace period: 1 minute
Message:
Expand Down
12 changes: 8 additions & 4 deletions cmd/edit/machinepool/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,20 @@ func editMachinePoolAutoscaling(machinePool *cmv1.MachinePool,
asBuilder := cmv1.NewMachinePoolAutoscaling()
changed := false

if machinePool.Autoscaling().MinReplicas() != minReplicas && minReplicas >= 1 {
asBuilder = asBuilder.MinReplicas(minReplicas)
newMin := machinePool.Autoscaling().MinReplicas()
newMax := machinePool.Autoscaling().MaxReplicas()

if machinePool.Autoscaling().MinReplicas() != minReplicas && minReplicas >= 0 {
newMin = minReplicas
changed = true
}
if machinePool.Autoscaling().MaxReplicas() != maxReplicas && maxReplicas >= 1 {
asBuilder = asBuilder.MaxReplicas(maxReplicas)
if machinePool.Autoscaling().MaxReplicas() != maxReplicas && maxReplicas >= 0 {
newMax = maxReplicas
changed = true
}

if changed {
asBuilder = asBuilder.MinReplicas(newMin).MaxReplicas(newMax)
return asBuilder
}
return nil
Expand Down
20 changes: 20 additions & 0 deletions cmd/edit/machinepool/machinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ var _ = Describe("Machinepool", func() {
asBuilder := cmv1.NewMachinePoolAutoscaling().MaxReplicas(3).MinReplicas(2)
Expect(builder).To(Equal(asBuilder))
})

It("editMachinePoolAutoscaling should allow 0 min replicas", func() {
machinePool, err := cmv1.NewMachinePool().
Autoscaling(cmv1.NewMachinePoolAutoscaling().MaxReplicas(2).MinReplicas(1)).
Build()
Expect(err).ToNot(HaveOccurred())
builder := editMachinePoolAutoscaling(machinePool, 0, 2)
asBuilder := cmv1.NewMachinePoolAutoscaling().MaxReplicas(2).MinReplicas(0)
Expect(builder).To(Equal(asBuilder))
})

It("editMachinePoolAutoscaling should allow 0 min and 0 max replicas", func() {
machinePool, err := cmv1.NewMachinePool().
Autoscaling(cmv1.NewMachinePoolAutoscaling().MaxReplicas(2).MinReplicas(1)).
Build()
Expect(err).ToNot(HaveOccurred())
builder := editMachinePoolAutoscaling(machinePool, 0, 0)
asBuilder := cmv1.NewMachinePoolAutoscaling().MaxReplicas(0).MinReplicas(0)
Expect(builder).To(Equal(asBuilder))
})
})

Context("isMultiAZMachinePool", func() {
Expand Down
10 changes: 7 additions & 3 deletions cmd/list/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/openshift/rosa/cmd/list/idp"
"github.com/openshift/rosa/cmd/list/ingress"
"github.com/openshift/rosa/cmd/list/instancetypes"
"github.com/openshift/rosa/cmd/list/kubeletconfig"
"github.com/openshift/rosa/cmd/list/machinepool"
"github.com/openshift/rosa/cmd/list/ocmroles"
"github.com/openshift/rosa/cmd/list/oidcconfig"
Expand Down Expand Up @@ -58,7 +59,8 @@ func init() {
Cmd.AddCommand(gates.Cmd)
Cmd.AddCommand(idp.Cmd)
Cmd.AddCommand(ingress.Cmd)
Cmd.AddCommand(machinepool.Cmd)
machinePoolCommand := machinepool.NewListMachinePoolCommand()
Cmd.AddCommand(machinePoolCommand)
Cmd.AddCommand(region.Cmd)
Cmd.AddCommand(upgrade.Cmd)
Cmd.AddCommand(user.Cmd)
Expand All @@ -76,6 +78,8 @@ func init() {
Cmd.AddCommand(rhRegion.Cmd)
Cmd.AddCommand(externalauthprovider.Cmd)
Cmd.AddCommand(breakglasscredential.Cmd)
kubeletconfig := kubeletconfig.NewListKubeletConfigsCommand()
Cmd.AddCommand(kubeletconfig)
flags := Cmd.PersistentFlags()
arguments.AddProfileFlag(flags)
arguments.AddRegionFlag(flags)
Expand All @@ -86,10 +90,10 @@ func init() {
oidcprovider.Cmd, cluster.Cmd,
breakglasscredential.Cmd, addon.Cmd,
externalauthprovider.Cmd, dnsdomains.Cmd,
gates.Cmd, idp.Cmd, ingress.Cmd, machinepool.Cmd,
gates.Cmd, idp.Cmd, ingress.Cmd, machinePoolCommand,
operatorroles.Cmd, region.Cmd, rhRegion.Cmd,
service.Cmd, tuningconfigs.Cmd, upgrade.Cmd,
user.Cmd, version.Cmd,
user.Cmd, version.Cmd, kubeletconfig,
}
arguments.MarkRegionDeprecated(Cmd, globallyAvailableCommands)
}
69 changes: 69 additions & 0 deletions cmd/list/kubeletconfig/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package kubeletconfig

import (
"context"
"fmt"
"os"
"text/tabwriter"

"github.com/spf13/cobra"

"github.com/openshift/rosa/pkg/kubeletconfig"
"github.com/openshift/rosa/pkg/ocm"
"github.com/openshift/rosa/pkg/output"
"github.com/openshift/rosa/pkg/rosa"
)

const (
use = "kubeletconfigs"
short = "List kubeletconfigs"
long = short
example = ` # List the kubeletconfigs for cluster 'foo'
rosa list kubeletconfig --cluster foo`
alias = "kubelet-configs"
)

func NewListKubeletConfigsCommand() *cobra.Command {
cmd := &cobra.Command{
Use: use,
Short: short,
Long: long,
Example: example,
Aliases: []string{alias},
Args: cobra.NoArgs,
Run: rosa.DefaultRunner(rosa.RuntimeWithOCM(), ListKubeletConfigRunner()),
}

output.AddFlag(cmd)
ocm.AddClusterFlag(cmd)
return cmd
}

func ListKubeletConfigRunner() rosa.CommandRunner {
return func(ctx context.Context, runtime *rosa.Runtime, command *cobra.Command, args []string) error {

cluster, err := runtime.OCMClient.GetCluster(runtime.GetClusterKey(), runtime.Creator)
if err != nil {
return err
}
kubeletConfigs, err := runtime.OCMClient.ListKubeletConfigs(ctx, cluster.ID())
if err != nil {
return err
}

if output.HasFlag() {
output.Print(kubeletConfigs)
} else {
if len(kubeletConfigs) == 0 {
runtime.Reporter.Infof("There are no KubeletConfigs for cluster '%s'.", runtime.ClusterKey)
return nil
}

writer := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
fmt.Fprint(writer, kubeletconfig.PrintKubeletConfigsForTabularOutput(kubeletConfigs))
return writer.Flush()
}

return nil
}
}
13 changes: 13 additions & 0 deletions cmd/list/kubeletconfig/cmd_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kubeletconfig

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestListKubeletConfigs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "List KubeletConfigs Suite")
}

0 comments on commit a6777cd

Please sign in to comment.