mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
enforce include-uninitialized in several kubectl commands
This commit is contained in:
@@ -52,8 +52,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ApplyAnnotationsFlag = "save-config"
|
||||
DefaultErrorExitCode = 1
|
||||
ApplyAnnotationsFlag = "save-config"
|
||||
DefaultErrorExitCode = 1
|
||||
IncludeUninitializedFlag = "include-uninitialized"
|
||||
)
|
||||
|
||||
type debugError interface {
|
||||
@@ -431,7 +432,7 @@ func AddDryRunFlag(cmd *cobra.Command) {
|
||||
}
|
||||
|
||||
func AddIncludeUninitializedFlag(cmd *cobra.Command) {
|
||||
cmd.Flags().Bool("include-uninitialized", false, "If true, include the object(s) that have not been realized yet. Such object(s) have a non-empty initializer list.")
|
||||
cmd.Flags().Bool(IncludeUninitializedFlag, false, `If true, the kubectl command applies to uninitialized objects. If explicitly set to false, this flag overrides other flags that make the kubectl commands apply to uninitialized objects, e.g., "--all". Objects with empty metadata.initializers are regarded as initialized.`)
|
||||
}
|
||||
|
||||
func AddPodRunningTimeoutFlag(cmd *cobra.Command, defaultTimeout time.Duration) {
|
||||
@@ -840,3 +841,25 @@ func ManualStrip(file []byte) []byte {
|
||||
}
|
||||
return stripped
|
||||
}
|
||||
|
||||
// ShouldIncludeUninitialized identifies whether to include uninitialized objects.
|
||||
// includeUninitialized is the default value.
|
||||
// Assume we can parse `all` and `selector` from cmd.
|
||||
func ShouldIncludeUninitialized(cmd *cobra.Command, includeUninitialized bool) bool {
|
||||
shouldIncludeUninitialized := includeUninitialized
|
||||
if cmd.Flags().Lookup("all") != nil && GetFlagBool(cmd, "all") {
|
||||
// include the uninitialized objects by default
|
||||
// unless explicitly set --include-uninitialized=false
|
||||
shouldIncludeUninitialized = true
|
||||
}
|
||||
if cmd.Flags().Lookup("selector") != nil && GetFlagString(cmd, "selector") != "" {
|
||||
// does not include the uninitialized objects by default
|
||||
// unless explicitly set --include-uninitialized=true
|
||||
shouldIncludeUninitialized = false
|
||||
}
|
||||
if cmd.Flags().Changed(IncludeUninitializedFlag) {
|
||||
// get explicit value
|
||||
shouldIncludeUninitialized = GetFlagBool(cmd, IncludeUninitializedFlag)
|
||||
}
|
||||
return shouldIncludeUninitialized
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user