Skip to content

Commit e0a9407

Browse files
Fixes for issues in 1.18 pre-release (#1016)
* Generated docs for xargs-apps * Fixed pluralization in xargs-apps * Fixed incorrect examples in xargs-apps * Changed xargs-apps into an experimental subcommand * Added extra comment in xargs-apps to allow exporting as a command * Fixed garbagecollector logging name * Added config watcher to garbagecollector logger to prevent a panic
1 parent a76a277 commit e0a9407

File tree

8 files changed

+102
-15
lines changed

8 files changed

+102
-15
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: "kf xargs-apps"
3+
weight: 100
4+
description: "Run a command for every App."
5+
---
6+
### Name
7+
8+
<code translate="no">kf xargs-apps</code> - Run a command for every App.
9+
10+
### Synopsis
11+
12+
<pre translate="no">kf xargs-apps [flags]</pre>
13+
14+
### Description
15+
16+
Run a command for every App in targeted spaces.
17+
18+
### Examples
19+
20+
<pre translate="no">
21+
# Example: restart all apps in all spaces
22+
kf xargs-apps --all-namespaces -- kf restart {{.Name}} --space {{.Space}}
23+
24+
# Example: restage all apps in all spaces
25+
kf xargs-apps --all-namespaces -- kf restage {{.Name}} --space {{.Space}}
26+
27+
# Example: stop all apps in spaces &#39;space1&#39; and &#39;space2&#39;
28+
kf xargs-apps --space space1,space2 -- kf stop {{.Name}} --space {{.Space}}
29+
30+
# Example: use kubectl to label all apps in the default space
31+
kf xargs-apps -- kubectl label apps -n {{.Space}} {{.Name}} environment=prod</pre>
32+
33+
### Flags
34+
35+
<dl>
36+
<dt><code translate="no">--all-namespaces</code></dt>
37+
<dd><p>Enables targeting all spaces in the cluster.</p>
38+
</dd>
39+
<dt><code translate="no">--dry-run</code></dt>
40+
<dd><p>Enables dry-run mode, commands are printed but will not be executed. (default true)</p>
41+
</dd>
42+
<dt><code translate="no">-h, --help</code></dt>
43+
<dd><p>help for xargs-apps</p>
44+
</dd>
45+
<dt><code translate="no">--resource-concurrency=<var translate="no">int</var></code></dt>
46+
<dd><p>Number of apps within a space that may be operated on in parallel. Total concurrency will be upto space-concurrency * app-concurrency. -1 for no limit. (default 1)</p>
47+
</dd>
48+
<dt><code translate="no">--space-concurrency=<var translate="no">int</var></code></dt>
49+
<dd><p>Number of spaces that may be operated on in parallel. -1 for no limit. (default -1)</p>
50+
</dd>
51+
</dl>
52+
53+
54+
### Inherited flags
55+
56+
These flags are inherited from parent commands.
57+
58+
<dl>
59+
<dt><code translate="no">--as=<var translate="no">string</var></code></dt>
60+
<dd><p>Username to impersonate for the operation.</p>
61+
</dd>
62+
<dt><code translate="no">--as-group=<var translate="no">strings</var></code></dt>
63+
<dd><p>Group to impersonate for the operation. Include this flag multiple times to specify multiple groups.</p>
64+
</dd>
65+
<dt><code translate="no">--config=<var translate="no">string</var></code></dt>
66+
<dd><p>Path to the Kf config file to use for CLI requests.</p>
67+
</dd>
68+
<dt><code translate="no">--kubeconfig=<var translate="no">string</var></code></dt>
69+
<dd><p>Path to the kubeconfig file to use for CLI requests.</p>
70+
</dd>
71+
<dt><code translate="no">--log-http</code></dt>
72+
<dd><p>Log HTTP requests to standard error.</p>
73+
</dd>
74+
<dt><code translate="no">--space=<var translate="no">string</var></code></dt>
75+
<dd><p>Space to run the command against. This flag overrides the currently targeted Space.</p>
76+
</dd>
77+
</dl>
78+
79+

pkg/kf/commands/apps/xargs_apps.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import (
99
)
1010

1111
const examples = `# Example: restart all apps in all spaces
12-
kf xargs-apps --all-spaces -- kf restart {{.Name}} --space {{.Space}}
12+
kf xargs-apps --all-namespaces -- kf restart {{.Name}} --space {{.Space}}
13+
1314
# Example: restage all apps in all spaces
14-
kf xargs-apps --all-spaces -- kf restage {{.Name}} --space {{.Space}}
15+
kf xargs-apps --all-namespaces -- kf restage {{.Name}} --space {{.Space}}
16+
1517
# Example: stop all apps in spaces 'space1' and 'space2'
1618
kf xargs-apps --space space1,space2 -- kf stop {{.Name}} --space {{.Space}}
19+
1720
# Example: use kubectl to label all apps in the default space
1821
kf xargs-apps -- kubectl label apps -n {{.Space}} {{.Name}} environment=prod`
1922

20-
// NewAppsCommand allows users to list apps.
23+
// NewXargsAppsCommand allows users to list apps.
2124
func NewXargsAppsCommand(p *config.KfParams, client spaces.Client) *cobra.Command {
2225
return genericcli.NewXargsCommand(
2326
apps.NewResourceInfo(),

pkg/kf/commands/dependencies/dependencies.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func newDependencies() []dependency {
117117
{
118118
Name: "Anthos Service Mesh",
119119
ShortNames: []string{"asm"},
120-
InfoURL: "/service-mesh/docs/gke-install-overview",
120+
InfoURL: "https://cloud.google.com/service-mesh/docs/gke-install-overview",
121121
// This version is fetched from the asmcli script. It needs to be
122122
// updated by hand until we have a programtic way to fetch it.
123123
ResolveVersion: staticVersionResolver("1.16.4-asm.2+config1"),
@@ -129,7 +129,7 @@ func newDependencies() []dependency {
129129
{
130130
Name: "Config Connector",
131131
ShortNames: []string{"kcc"},
132-
InfoURL: "/config-connector/docs/how-to/advanced-install",
132+
InfoURL: "https://cloud.google.com//config-connector/docs/how-to/advanced-install",
133133
// This version needs to be updated by hand until we have a
134134
// programtic way to fetch it.
135135
ResolveVersion: staticVersionResolver("1.66.0"),

pkg/kf/commands/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ func NewRawKfCommand() *cobra.Command {
132132
InjectPush(p),
133133
InjectDelete(p),
134134
InjectApps(p),
135-
InjectXargsApps(p),
136135
InjectGetApp(p),
137136
InjectStart(p),
138137
InjectStop(p),
@@ -282,6 +281,10 @@ func NewRawKfCommand() *cobra.Command {
282281
"Buildpacks",
283282
InjectWrapV2Buildpack(p),
284283
),
284+
utils.ExperimentalCommandGroup(
285+
"Bulk Actions",
286+
InjectXargsApps(p),
287+
),
285288
{
286289
Name: "Other Commands",
287290
Commands: []*cobra.Command{

pkg/kf/internal/genericcli/xargs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewXargsCommand(t Type, p *config.KfParams, spacesClient spaces.Client, opt
6060
if options.Short() != "" {
6161
short = options.Short()
6262
} else {
63-
short = fmt.Sprintf("Run a command for every %s.", options.PluralFriendlyName())
63+
short = fmt.Sprintf("Run a command for every %s.", t.FriendlyName())
6464
}
6565

6666
var long string
@@ -96,9 +96,9 @@ func NewXargsCommand(t Type, p *config.KfParams, spacesClient spaces.Client, opt
9696
}
9797

9898
if flags.allSpaces {
99-
logger.Infof("Xargs %s in all spaces", options.PluralFriendlyName())
99+
logger.Infof("# Xargs %s in all spaces", options.PluralFriendlyName())
100100
} else if t.Namespaced() {
101-
logger.Infof("Xargs %s in space: %s", options.PluralFriendlyName(), p.Space)
101+
logger.Infof("# Xargs %s in space: %s", options.PluralFriendlyName(), p.Space)
102102
}
103103

104104
labelSelector := labels.Set{}

pkg/kf/internal/genericcli/xargs_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ func TestXargsCommand_docs(t *testing.T) {
5353
"general": {
5454
genericType: typ,
5555
wantUse: "xargs-mycustomtypes",
56-
wantShort: "Run a command for every MyCustomTypes.",
56+
wantShort: "Run a command for every MyCustomType.",
5757
wantLong: "Run a command for every MyCustomType in targeted spaces.",
5858
wantExample: "kf xargs-mycustomtypes",
5959
},
6060
"with custom example": {
6161
genericType: typ,
6262
wantUse: "xargs-mycustomtypes",
63-
wantShort: "Run a command for every MyCustomTypes.",
63+
wantShort: "Run a command for every MyCustomType.",
6464
wantLong: "Run a command for every MyCustomType in targeted spaces.",
6565
wantExample: "a custom example",
6666
opts: []XargsOption{
@@ -70,7 +70,7 @@ func TestXargsCommand_docs(t *testing.T) {
7070
"with aliases": {
7171
genericType: typ,
7272
wantUse: "xargs-mycustomtypes",
73-
wantShort: "Run a command for every MyCustomTypes.",
73+
wantShort: "Run a command for every MyCustomType.",
7474
wantLong: "Run a command for every MyCustomType in targeted spaces.",
7575
wantExample: "kf xargs-mycustomtypes",
7676
wantAliases: []string{"a", "b"},
@@ -157,7 +157,7 @@ func TestNewXargsCommand(t *testing.T) {
157157
Namespace("my-ns").
158158
Create(ctx, obj, metav1.CreateOptions{})
159159
},
160-
wantOut: "Xargs Apps in space: my-ns\n# Command for space=my-ns App=some-object-name\n'my-ns some-object-name'\n# Run with --dry-run=false to apply.\n",
160+
wantOut: "# Xargs Apps in space: my-ns\n# Command for space=my-ns App=some-object-name\n'my-ns some-object-name'\n# Run with --dry-run=false to apply.\n",
161161
},
162162
"cluster type": {
163163
t: clusterType,
@@ -197,7 +197,7 @@ func TestNewXargsCommand(t *testing.T) {
197197
setup: func(ctx context.Context, t *testing.T, mocks *mocks) {
198198
mocks.p.Space = "ns1,ns2"
199199
},
200-
wantOut: "Xargs Apps in space: ns1,ns2\n# Command for space=ns1 App=app1\n'ns1 app1'\n# Command for space=ns1 App=app2\n'ns1 app2'\n# Command for space=ns2 App=app3\n'ns2 app3'\n# Command for space=ns2 App=app4\n'ns2 app4'\n# Run with --dry-run=false to apply.\n",
200+
wantOut: "# Xargs Apps in space: ns1,ns2\n# Command for space=ns1 App=app1\n'ns1 app1'\n# Command for space=ns1 App=app2\n'ns1 app2'\n# Command for space=ns2 App=app3\n'ns2 app3'\n# Command for space=ns2 App=app4\n'ns2 app4'\n# Run with --dry-run=false to apply.\n",
201201
},
202202
}
203203

pkg/reconciler/garbagecollector/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const GarbageCollectionInterval time.Duration = 5 * time.Minute
3131

3232
// NewController creates a new controller capable of reconciling Kf Apps.
3333
func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
34-
logger := reconciler.NewControllerLogger(ctx, "apps.kf.dev")
34+
logger := reconciler.NewControllerLogger(ctx, "garbagecollector.kf.dev")
3535

3636
// Get informers off context
3737
buildInformer := buildinformer.Get(ctx)

pkg/reconciler/garbagecollector/reconciler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, key string) error {
6060

6161
func (r *Reconciler) garbageCollectApp(ctx context.Context, namespace, name string) (err error) {
6262
logger := logging.FromContext(ctx)
63+
ctx = r.kfConfigStore.ToContext(ctx)
64+
6365
app, err := r.appLister.Apps(namespace).Get(name)
6466
switch {
6567
case apierrs.IsNotFound(err):

0 commit comments

Comments
 (0)