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

install: add --cluster-specific flag to generate #40548

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.