-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
Introduce new flag "--include-uninitialized" to kubectl #50497
Changes from all commits
6b24fe2
884a4b1
789a959
be0cadd
8a6a25f
d80ff0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: super-admin | ||
initializers: | ||
pending: | ||
- name: podimage.initializer.com | ||
labels: | ||
clusterrolebinding: super | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: admin | ||
subjects: | ||
- apiGroup: rbac.authorization.k8s.io | ||
kind: User | ||
name: super-admin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: web | ||
initializers: | ||
pending: | ||
- name: podimage.initializer.com | ||
labels: | ||
run: web | ||
spec: | ||
replicas: 5 | ||
selector: | ||
matchLabels: | ||
run: web | ||
template: | ||
metadata: | ||
labels: | ||
run: web | ||
spec: | ||
containers: | ||
- image: nginx:1.10 | ||
name: web | ||
ports: | ||
- containerPort: 80 | ||
protocol: TCP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: redis-master | ||
labels: | ||
app: redis | ||
role: master | ||
tier: backend | ||
initializers: | ||
pending: | ||
- name: podimage.initializer.com | ||
spec: | ||
ports: | ||
- port: 6379 | ||
targetPort: 6379 | ||
selector: | ||
app: redis | ||
role: master | ||
tier: backend |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,8 @@ var ( | |
|
||
This command will hide resources that have completed, such as pods that are | ||
in the Succeeded or Failed phases. You can see the full results for any | ||
resource by providing the '--show-all' flag. | ||
resource by providing the '--show-all' flag, but this flag does not include | ||
the uninitialized objects by default, unless '--include-uninitialized' is explicitly set. | ||
|
||
By specifying the output as 'template' and providing a Go template as the value | ||
of the --template flag, you can filter the attributes of the fetched resources.`) | ||
|
@@ -127,7 +128,8 @@ func NewCmdGet(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comman | |
} | ||
cmdutil.AddPrinterFlags(cmd) | ||
cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)") | ||
cmd.Flags().BoolP("watch", "w", false, "After listing/getting the requested object, watch for changes.") | ||
cmdutil.AddIncludeUninitializedFlag(cmd) | ||
cmd.Flags().BoolP("watch", "w", false, "After listing/getting the requested object, watch for changes. Uninitialized objects are excluded if no object name is provided.") | ||
cmd.Flags().Bool("watch-only", false, "Watch for changes to the requested object(s), without listing/getting first.") | ||
cmd.Flags().Bool("show-kind", false, "If present, list the resource type for the requested object(s).") | ||
cmd.Flags().Bool("all-namespaces", false, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.") | ||
|
@@ -201,6 +203,15 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ | |
|
||
// handle watch separately since we cannot watch multiple resource types | ||
isWatch, isWatchOnly := cmdutil.GetFlagBool(cmd, "watch"), cmdutil.GetFlagBool(cmd, "watch-only") | ||
|
||
var includeUninitialized bool | ||
if isWatch && len(args) == 2 { | ||
// include the uninitialized one for watching on a single object | ||
// unless explicitly set --include-uninitialized=false | ||
includeUninitialized = true | ||
} | ||
includeUninitialized = cmdutil.ShouldIncludeUninitialized(cmd, includeUninitialized) | ||
|
||
if isWatch || isWatchOnly { | ||
builder, err := f.NewUnstructuredBuilder(true) | ||
if err != nil { | ||
|
@@ -212,6 +223,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ | |
FilenameParam(enforceNamespace, &options.FilenameOptions). | ||
SelectorParam(selector). | ||
ExportParam(export). | ||
IncludeUninitialized(includeUninitialized). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is affecting WATCH verb. @caesarxuchao It's not clear to me what the behavior should be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ResourceTypeOrNameArgs(true, args...). | ||
SingleResourceType(). | ||
Latest(). | ||
|
@@ -301,6 +313,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ | |
FilenameParam(enforceNamespace, &options.FilenameOptions). | ||
SelectorParam(selector). | ||
ExportParam(export). | ||
IncludeUninitialized(includeUninitialized). | ||
ResourceTypeOrNameArgs(true, args...). | ||
ContinueOnError(). | ||
Latest(). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you add the flag to edit command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mengqiy No. This is the side effect since
options.Complete
has been changed. We've not planed addinginclude-uninitialized
flag tokubectl edit
. @caesarxuchao @ahmetb Correct me if I'm wrong.I've added below codes to method
Complete(...)
, so that it will not break currentkubectl edit
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
include-uninitialized
should be plumbed to every commands.kubectl edit
user should be able to edit the uninitialized objects if they specify--include-uninitialized=true
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(to clarify again, my understanding is that they should NOT need --include-uninitialized, if they're referring to object by name, i.e.
kubectl edit pod/foo
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. If the name of the object is provided, kubectl always show it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dixudx I think we need that flag per #49035 (comment). Did I miss some something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mengqiy You're right. I forgot to add here. Sorry for that. Will add it later when finishing the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caesarxuchao Currently we've only enabled
--include-uninitialized
in a few commands. To make it a global flag, we may need to make rules for every subcommand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dixudx could you give me some examples of the subcommands that don't support
--include-uninitialized
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caesarxuchao My mistake. Seems we have already supported them well. After a deep search, I found we only need to enable
--include-uninitialized
for subcommands that would request a group of resources. For a single specific resource, there is no need.