Skip to content

Commit

Permalink
ci: don't always generate CRDs in golden files (#5160)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahabana authored Oct 18, 2022
1 parent da91c50 commit aaedb07
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 31,984 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type InstallControlPlaneArgs struct {
ExperimentalGatewayAPI bool `helm:"experimental.gatewayAPI"`
ValueFiles []string
Values []string
SkipKinds []string
// APIVersions is a hidden, internal option
APIVersions []string
DumpValues bool
Expand Down
6 changes: 5 additions & 1 deletion app/kumactl/cmd/install/install_control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ This command requires that the KUBECONFIG environment is set`,
return errors.Wrap(err, "Failed to render helm template files")
}

sortedResources, err := k8s.SortResourcesByKind(renderedFiles)
sortedResources, err := k8s.SortResourcesByKind(renderedFiles, args.SkipKinds...)
if err != nil {
return errors.Wrap(err, "Failed to sort resources by kind")
}
Expand Down Expand Up @@ -217,6 +217,10 @@ This command requires that the KUBECONFIG environment is set`,
cmd.Flags().BoolVar(&args.ExperimentalGatewayAPI, "experimental-gatewayapi", false, "install experimental Gateway API support")
cmd.Flags().StringSliceVarP(&args.ValueFiles, "values", "f", []string{}, "specify values in a YAML file or '-' for stdin. This is similar to `helm template <chart> -f ...`")
cmd.Flags().StringArrayVar(&args.Values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2), This is similar to `helm template <chart> --set ...` to use set-file or set-string just use helm instead")
cmd.Flags().StringArrayVar(&args.SkipKinds, "skip-kinds", []string{}, "INTERNAL: A list of kubernetes kinds to not generate (useful, to ignore CRDs for example)")
if err := cmd.Flags().MarkHidden("skip-kinds"); err != nil {
panic(err.Error())
}

// This is used for testing the install command without a cluster
cmd.Flags().StringArrayVar(&args.APIVersions, "api-versions", []string{}, "INTERNAL: Kubernetes api versions used for Capabilities.APIVersions")
Expand Down
44 changes: 26 additions & 18 deletions app/kumactl/cmd/install/install_control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var _ = Describe("kumactl install control-plane", func() {
"control-plane",
"--tls-general-secret", "general-tls-secret",
"--tls-general-ca-bundle", "XYZ",
"--values",
inputFile,
"--skip-kinds", "CustomResourceDefinition",
"--values", inputFile,
},
)
rootCmd.SetOut(stdout)
Expand Down Expand Up @@ -91,9 +91,10 @@ var _ = Describe("kumactl install control-plane", func() {
}())

type testCase struct {
stdin string
extraArgs []string
goldenFile string
stdin string
extraArgs []string
goldenFile string
includeCRDs bool
}
DescribeTable("should generate Kubernetes resources",
func(given testCase) {
Expand All @@ -103,18 +104,21 @@ var _ = Describe("kumactl install control-plane", func() {
rootCtx.InstallCpContext.Args.ControlPlane_image_tag = "0.0.1"
rootCtx.InstallCpContext.Args.DataPlane_image_tag = "0.0.1"
rootCtx.InstallCpContext.Args.DataPlane_initImage_tag = "0.0.1"
args := []string{
"install",
"control-plane",
"--tls-general-secret", "general-tls-secret",
"--tls-general-ca-bundle", "XYZ",
}
if !given.includeCRDs {
args = append(args, "--skip-kinds", "CustomResourceDefinition")
}

args = append(args, given.extraArgs...)

// given
rootCmd := cmd.NewRootCmd(rootCtx)
rootCmd.SetArgs(append(
[]string{
"install",
"control-plane",
"--tls-general-secret", "general-tls-secret",
"--tls-general-ca-bundle", "XYZ",
},
given.extraArgs...,
))
rootCmd.SetArgs(args)
if given.stdin != "" {
stdin := &bytes.Buffer{}
stdin.WriteString(given.stdin)
Expand All @@ -138,7 +142,8 @@ var _ = Describe("kumactl install control-plane", func() {
extraArgs: []string{
"--without-kubernetes-connection",
},
goldenFile: "install-control-plane.defaults.golden.yaml",
includeCRDs: true,
goldenFile: "install-control-plane.defaults.golden.yaml",
}),
Entry("should override default env-vars with values supplied", testCase{
extraArgs: []string{
Expand Down Expand Up @@ -247,7 +252,8 @@ var _ = Describe("kumactl install control-plane", func() {
"--set",
"controlPlane.mode=zone,controlPlane.zone=zone-1,controlPlane.kdsGlobalAddress=grpcs://foo.com",
},
goldenFile: "install-control-plane.with-helm-set.yaml",
includeCRDs: true,
goldenFile: "install-control-plane.with-helm-set.yaml",
}),
Entry("should work with --values", testCase{
extraArgs: []string{
Expand All @@ -272,14 +278,16 @@ controlPlane:
"--api-versions", fmt.Sprintf("%s/%s", gatewayapi.GroupVersion.String(), "GatewayClass"),
"--experimental-gatewayapi",
},
goldenFile: "install-control-plane.gateway-api-present.yaml",
includeCRDs: true,
goldenFile: "install-control-plane.gateway-api-present.yaml",
}),
Entry("should not add GatewayClass if experimental not enabled", testCase{
extraArgs: []string{
"--without-kubernetes-connection",
"--api-versions", fmt.Sprintf("%s/%s", gatewayapi.GroupVersion.String(), "GatewayClass"),
},
goldenFile: "install-control-plane.gateway-api-present-not-enabled.yaml",
includeCRDs: true,
goldenFile: "install-control-plane.gateway-api-present-not-enabled.yaml",
}),
)

Expand Down
Loading

0 comments on commit aaedb07

Please sign in to comment.