Skip to content

Commit f692af6

Browse files
committed
initial commit after migrating from client-contrib
0 parents  commit f692af6

File tree

3,029 files changed

+922250
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,029 files changed

+922250
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kn-admin

OWNERS

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
approvers:
2+
- zhanggbj
3+
- rhuss
4+
- maximilien
5+
- navidshaikh
6+
# Also including TOC members as backup:
7+
- evankanderson
8+
- grantr
9+
- markusthoemmes
10+
- mattmoor
11+
- tcnghia

README.adoc

+255
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
## kn-admin
2+
3+
`kn admin` helps for Knative configuration when running on a Kubernetes cluster.
4+
5+
### Description
6+
7+
This kn-admin plugin is designed to help administrators and operators better manage a Knative platform installation with kn CLI.
8+
The plugin’s main objective is to make administration and operation workflows easier, for instance by making it easy to accomplish
9+
tasks such as feature flags enablement or disablement with one command, instead of many manual steps like modifying ConfigMaps or yaml files.
10+
11+
### Usage
12+
13+
----
14+
A plugin of kn client to manage Knative for administrators.
15+
16+
For example:
17+
kn admin domain set - to set Knative route domain
18+
kn admin private-registry enable - to enable deployment from the private registry
19+
kn admin autoscaling update - to manage autoscaling config
20+
21+
Usage:
22+
kn admin [command]
23+
24+
Available Commands:
25+
autoscaling Manage autoscaling config
26+
domain Manage route domain
27+
help Help about any command
28+
registry Manage registry
29+
version Prints the plugin version
30+
31+
Flags:
32+
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml)
33+
-h, --help help for kn admin
34+
-t, --toggle Help message for toggle
35+
36+
Use "kn admin [command] --help" for more information about a command.
37+
----
38+
39+
#### `kn admin domain`
40+
41+
----
42+
Set default route domain or route domain for Service with selectors. For example:
43+
44+
kn admin domain set - to set Knative route domain
45+
46+
Usage:
47+
kn admin domain [flags]
48+
kn admin domain [command]
49+
50+
Available Commands:
51+
set set route domain
52+
unset unset route domain
53+
54+
Flags:
55+
-h, --help help for domain
56+
57+
Global Flags:
58+
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml)
59+
60+
Use "admin domain [command] --help" for more information about a command.
61+
62+
----
63+
64+
#### `kn admin registry`
65+
66+
----
67+
Manage Service deployment from a private registry
68+
69+
For example:
70+
71+
kn admin registry add \
72+
--secret=[SECRET_NAME]
73+
--server=[REGISTRY_SERVER_URL] \
74+
--email=[REGISTRY_EMAIL] \
75+
--username=[REGISTRY_USER] \
76+
--password=[REGISTRY_PASSWORD]
77+
78+
Usage:
79+
kn admin registry [command]
80+
81+
Available Commands:
82+
add Add registry with credentials
83+
help Help about any command
84+
remove Remove registry settings
85+
86+
Flags:
87+
-h, --help help for registry
88+
-n, --namespace string the namespace to manage registries
89+
-s, --serviceaccount string the serviceaccount to save imagePullSecrets
90+
91+
Global Flags:
92+
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml)
93+
94+
Use "kn admin registry [command] --help" for more information about a command.
95+
----
96+
97+
#### `kn admin autoscaling`
98+
99+
----
100+
Manage autoscaling provided by Knative Pod Autoscaler (KPA). For example:
101+
102+
kn admin autoscaling update - to manage autoscaling config
103+
104+
Usage:
105+
kn admin autoscaling [command]
106+
107+
Available Commands:
108+
update update autoscaling config
109+
110+
Flags:
111+
-h, --help help for autoscaling
112+
113+
Global Flags:
114+
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml)
115+
116+
Use "kn admin autoscaling [command] --help" for more information about a command.
117+
118+
----
119+
120+
#### `kn admin profiling`
121+
122+
----
123+
Enable Knative Serving components profiling and download profiling data
124+
125+
Usage:
126+
kn admin profiling [flags]
127+
128+
Aliases:
129+
profiling, prof
130+
131+
Examples:
132+
133+
# To enable Knative Serving profiling
134+
kn admin profiling --enable
135+
136+
# To download heap profiling data of autoscaler
137+
kn admin profiling --target autoscaler --heap
138+
139+
# To download 2 minutes execution trace data of networking-istio
140+
kn admin profiling --target networking-istio --trace 2m
141+
142+
# To download go routing block and memory allocations data of activator and save them to /tmp
143+
kn admin profiling --target activator --block --mem-allocs --save-to /tmp
144+
145+
# To download all available profiling data for specified pod activator-5979f56548
146+
kn admin profiling --target activator-5979f56548 --all
147+
148+
149+
Flags:
150+
--all Download all available profiling data
151+
--block Download go routine blocking data
152+
--cpu string Download cpu profiling data, you can specify a profiling data duration with 's' for second(s), 'm' for minute(s) and 'h' for hour(s), e.g: '1m' for one minute (default "5s")
153+
--disable Disable Knative Serving profiling
154+
--enable Enable Knative Serving profiling
155+
--goroutine Download stack traces of all current goroutines data
156+
--heap Download heap profiling data
157+
-h, --help help for profiling
158+
--mem-allocs Download memory allocations data
159+
--mutex Download holders of contended mutexes data
160+
-s, --save-to string The path to save the downloaded profiling data, if not speicifed, the data will be saved in current working folder
161+
-t, --target string The profiling target. It can be a Knative Serving component name or a specific pod name, e.g: 'activator' or 'activator-586d468c99-w59cm'
162+
--thread-create Download stack traces that led to the creation of new OS threads data
163+
--trace string Download execution trace data, you can specify a trace data duration with 's' for second(s), 'm' for minute(s) and 'h' for hour(s), e.g: '1m' for one minute (default "5s")
164+
165+
Global Flags:
166+
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml)
167+
168+
----
169+
### Examples
170+
171+
#### As a Knative administrator, I want to update Knative route domain with my custom domain.
172+
173+
174+
.Update the default route domain if --selector no specified
175+
====
176+
----
177+
$ kn admin domain set --custom-domain mydomain.com
178+
Set Knative route domain mydomain.com
179+
----
180+
====
181+
182+
.Update a custom domain with --selector and Service with a label app=v1 will use test.com
183+
====
184+
----
185+
$ kn admin domain set --custom-domain test.com --selector app=v1
186+
Set Knative route domain test.com with selector [app=v1]
187+
----
188+
====
189+
190+
.Unset a route domain
191+
====
192+
----
193+
$ kn-admin domain unset --custom-domain mydomain.com
194+
Unset Knative route domain mydomain.com
195+
----
196+
====
197+
198+
#### As a Knative administrator, I want to enable deploying from private registry.
199+
200+
.Enable a private registry with given credentials for Service creation.
201+
=====
202+
-----
203+
$ kn admin registry add \
204+
--secret=[SECRET_NAME] \
205+
--server=[REGISTRY_SERVER_URL] \
206+
--email=[REGISTRY_EMAIL] \
207+
--username=[REGISTRY_USER] \
208+
--password=[REGISTRY_PASSWORD] \
209+
--namespace=[NAMESPACE] \
210+
--serviceaccount=[SERVICE_ACCOUNT]
211+
-----
212+
=====
213+
214+
.Remove a private registry by server and username.
215+
=====
216+
-----
217+
$ kn admin registry remove \
218+
--username=[REGISTRY_USER] \
219+
--server=[REGISTRY_SERVER_URL] \
220+
--namespace=[NAMESPACE] \
221+
--serviceaccount=[SERVICE_ACCOUNT]
222+
-----
223+
=====
224+
225+
#### As a Knative administrator, I want to enable scale-to-zero for autoscaling.
226+
227+
.Enable scale-to-zero for autoscaling.
228+
=====
229+
-----
230+
$ kn admin autoscaling update --scale-to-zero
231+
Updated Knative autoscaling config enable-scale-to-zero: true
232+
-----
233+
=====
234+
235+
#### As a Knative administrator, I want to enable Knative Serving profiling and download profile data.
236+
237+
.Enable Knative Serving profiling.
238+
=====
239+
-----
240+
$ kn admin profiling --enable
241+
Knative Serving profiling is enabled
242+
-----
243+
=====
244+
245+
.Download 5 seconds cpu profiling data of activator component and save data to /tmp folder
246+
=====
247+
-----
248+
$ kn admin profiling --target activator --cpu 5s --save-to /tmp
249+
Starting to download profiling data for pod activator-586d468c99-w59cm...
250+
Saving 5 second(s) cpu profiling data to /tmp/activator-586d468c99-w59cm_cpu_5s_20200725165758
251+
Forwarding from 127.0.0.1:18008 -> 8008
252+
Forwarding from [::1]:18008 -> 8008
253+
Handling connection for 18008
254+
-----
255+
=====

cmd/kn-admin.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright © 2020 The Knative Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package main
15+
16+
import (
17+
"os"
18+
19+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
20+
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
21+
"knative.dev/client-contrib/plugins/admin/core"
22+
)
23+
24+
func main() {
25+
if err := core.NewAdminCommand().Execute(); err != nil {
26+
os.Exit(1)
27+
}
28+
}

core/root.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright © 2020 The Knative Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package core
16+
17+
import (
18+
"fmt"
19+
"os"
20+
21+
homedir "github.com/mitchellh/go-homedir"
22+
"github.com/spf13/cobra"
23+
"github.com/spf13/viper"
24+
"knative.dev/client-contrib/plugins/admin/pkg"
25+
"knative.dev/client-contrib/plugins/admin/pkg/command"
26+
"knative.dev/client-contrib/plugins/admin/pkg/command/autoscaling"
27+
"knative.dev/client-contrib/plugins/admin/pkg/command/domain"
28+
"knative.dev/client-contrib/plugins/admin/pkg/command/profiling"
29+
private_registry "knative.dev/client-contrib/plugins/admin/pkg/command/registry"
30+
)
31+
32+
var cfgFile string
33+
34+
// NewAdminCommand represents the base command when called without any subcommands
35+
func NewAdminCommand(params ...pkg.AdminParams) *cobra.Command {
36+
p := &pkg.AdminParams{}
37+
p.Initialize()
38+
39+
rootCmd := &cobra.Command{
40+
Use: "kn\u00A0admin",
41+
Short: "A plugin of kn client to manage Knative",
42+
Long: `kn admin: a plugin of kn client to manage Knative for administrators`,
43+
44+
// disable printing usage when error occurs
45+
SilenceUsage: true,
46+
}
47+
cobra.OnInitialize(initConfig)
48+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/kn/plugins/admin.yaml)")
49+
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
50+
rootCmd.SetOut(os.Stdout)
51+
rootCmd.AddCommand(domain.NewDomainCmd(p))
52+
rootCmd.AddCommand(private_registry.NewPrivateRegistryCmd(p))
53+
rootCmd.AddCommand(autoscaling.NewAutoscalingCmd(p))
54+
rootCmd.AddCommand(profiling.NewProfilingCommand(p))
55+
rootCmd.AddCommand(command.NewVersionCommand())
56+
57+
// Add default help page if there's unknown command
58+
rootCmd.InitDefaultHelpCmd()
59+
return rootCmd
60+
}
61+
62+
// initConfig reads in config file and ENV variables if set.
63+
func initConfig() {
64+
if cfgFile != "" {
65+
// Use config file from the flag.
66+
viper.SetConfigFile(cfgFile)
67+
} else {
68+
// Find home directory.
69+
home, err := homedir.Dir()
70+
if err != nil {
71+
fmt.Println(err)
72+
os.Exit(1)
73+
}
74+
75+
// Search config in home directory with name ".admin" (without extension).
76+
viper.AddConfigPath(home)
77+
viper.SetConfigName(".admin")
78+
}
79+
80+
viper.AutomaticEnv() // read in environment variables that match
81+
82+
// If a config file is found, read it in.
83+
if err := viper.ReadInConfig(); err == nil {
84+
fmt.Println("Using config file:", viper.ConfigFileUsed())
85+
}
86+
}

0 commit comments

Comments
 (0)