Skip to content

Commit

Permalink
install: add --cluster-specific flag to generate (istio#40548)
Browse files Browse the repository at this point in the history
This allows `manifest generate` to use cluster specific settings as
well.

The only install method left is `helm template`; I have a bug filed in
helm/helm#11240.
  • Loading branch information
howardjohn authored and mt-inside committed Oct 12, 2022
1 parent 54a8f32 commit 57431c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 25 additions & 1 deletion operator/cmd/mesh/manifest-generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"istio.io/istio/operator/pkg/name"
"istio.io/istio/operator/pkg/object"
"istio.io/istio/operator/pkg/util/clog"
"istio.io/istio/pkg/kube"
"istio.io/pkg/log"
)

Expand All @@ -36,6 +37,15 @@ type ManifestGenerateArgs struct {
InFilenames []string
// OutFilename is the path to the generated output directory.
OutFilename string

// EnableClusterSpecific determines if the current Kubernetes cluster will be used to autodetect values.
// If false, generic defaults will be used. This is useful when generating once and then applying later.
EnableClusterSpecific bool
// KubeConfigPath is the path to kube config file.
KubeConfigPath string
// Context is the cluster context in the kube config
Context string

// Set is a string with element format "path=value" where path is an IstioOperator path and the value is a
// value to set the node at that path to.
Set []string
Expand Down Expand Up @@ -74,6 +84,11 @@ func addManifestGenerateFlags(cmd *cobra.Command, args *ManifestGenerateArgs) {
cmd.PersistentFlags().StringSliceVar(&args.Components, "component", nil, ComponentFlagHelpStr)
cmd.PersistentFlags().StringSliceVar(&args.Filter, "filter", nil, "")
_ = cmd.PersistentFlags().MarkHidden("filter")

cmd.PersistentFlags().StringVarP(&args.KubeConfigPath, "kubeconfig", "c", "", KubeConfigFlagHelpStr+" Requires --cluster-specific.")
cmd.PersistentFlags().StringVar(&args.Context, "context", "", ContextFlagHelpStr+" Requires --cluster-specific.")
cmd.PersistentFlags().BoolVar(&args.EnableClusterSpecific, "cluster-specific", false,
"If enabled, the current cluster will be checked for cluster-specific setting detection.")
}

func ManifestGenerateCmd(rootArgs *RootArgs, mgArgs *ManifestGenerateArgs, logOpts *log.Options) *cobra.Command {
Expand Down Expand Up @@ -115,8 +130,17 @@ func ManifestGenerate(args *RootArgs, mgArgs *ManifestGenerateArgs, logopts *log
return fmt.Errorf("could not configure logs: %s", err)
}

var kubeClient kube.CLIClient
if mgArgs.EnableClusterSpecific {
kc, _, err := KubernetesClients(mgArgs.KubeConfigPath, mgArgs.Context, l)
if err != nil {
return err
}
kubeClient = kc
}

manifests, _, err := manifest.GenManifests(mgArgs.InFilenames, applyFlagAliases(mgArgs.Set, mgArgs.ManifestsPath, mgArgs.Revision),
mgArgs.Force, mgArgs.Filter, nil, l)
mgArgs.Force, mgArgs.Filter, kubeClient, l)
if err != nil {
return err
}
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/cluster-specific-generate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: release-notes/v2
kind: feature
area: installation
releaseNotes:
- |
**Added** a `--cluster-specific` flag to `istioctl manifest generate`. When this is set, the current cluster context will be used to determine dynamic default settings, mirroring `istioctl install`.

0 comments on commit 57431c2

Please sign in to comment.