This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
feature: Initialize kn admin plugin #2
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ approvers: | |
- rhuss | ||
- maximilien | ||
- navidshaikh | ||
- zhanggbj | ||
# TOC members as a fallback | ||
- mattmoor | ||
- evankanderson |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
## kn-admin | ||
|
||
A kn plugin for Knative cluster management. | ||
|
||
`kn hello` prints out a friendly message to the user. | ||
zhanggbj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Description | ||
|
||
This kn-admin plugin is designed to help administrators and operators better manage a Knative platform installation with kn CLI. | ||
The plugin’s main objective is to make administration and operation workflows easier, for instance by making it easy to accomplish | ||
tasks such as feature flags enablement or disablement with one command, instead of many manual steps like modifying ConfigMaps or yaml files. | ||
|
||
### Usage | ||
|
||
---- | ||
A plugin of kn client to manage Knative for administrators. | ||
zhanggbj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
For example: | ||
kn admin domain set - to set Knative route domain | ||
kn admin private-registry enable - to enable deployment from the private registry | ||
|
||
Usage: | ||
zhanggbj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kn admin [command] | ||
|
||
Available Commands: | ||
domain Manage route domain | ||
help Help about any command | ||
private-registry Manage private-registry | ||
|
||
Flags: | ||
--config string config file (default is $HOME/.config/kn/plugins/kn-admin.yaml) | ||
-h, --help help for admin | ||
-t, --toggle Help message for toggle | ||
|
||
Use "admin [command] --help" for more information about a command. | ||
---- | ||
|
||
#### `kn admin domain` | ||
|
||
---- | ||
Set default route domain or route domain for Service with selectors. For example: | ||
|
||
kn admin domain set - to set Knative route domain | ||
|
||
Usage: | ||
kn admin domain [flags] | ||
kn admin domain [command] | ||
|
||
Available Commands: | ||
set set route domain | ||
|
||
Flags: | ||
-h, --help help for domain | ||
|
||
Global Flags: | ||
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml) | ||
|
||
Use "admin domain [command] --help" for more information about a command. | ||
|
||
---- | ||
|
||
#### `kn admin private-registry` | ||
|
||
---- | ||
Manage Service deployment from a private registry | ||
For example: | ||
|
||
kn admin private-registry enable \ | ||
--secret-name=[SECRET_NAME] | ||
--docker-server=[PRIVATE_REGISTRY_SERVER_URL] \ | ||
--docker-email=[PRIVATE_REGISTRY_EMAIL] \ | ||
--docker-username=[PRIVATE_REGISTRY_USER] \ | ||
--docker-password=[PRIVATE_REGISTRY_PASSWORD] | ||
zhanggbj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Usage: | ||
kn admin private-registry [command] | ||
|
||
Available Commands: | ||
enable enable Service deployment from a private registry | ||
zhanggbj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Flags: | ||
-h, --help help for private-registry | ||
|
||
Global Flags: | ||
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml) | ||
|
||
Use "admin private-registry [command] --help" for more information about a command. | ||
|
||
---- | ||
|
||
### Examples | ||
|
||
#### As a Knative administrator, I want to update Knative route domain with my custom domain. | ||
|
||
|
||
.Update the default route domain if --selector no specified | ||
==== | ||
---- | ||
$ kn admin domain set --custom-domain mydomain.com | ||
Updated Knative route domain mydomain.com | ||
---- | ||
==== | ||
|
||
.Update a custom domain with --selector and Service with a label app=v1 will use test.com | ||
==== | ||
---- | ||
$ kn admin domain set --custom-domain test.com --selector app=v1 | ||
Updated Knative route domain test.com | ||
---- | ||
==== | ||
|
||
#### As a Knative administrator, I want to enable deploying from private registry. | ||
|
||
.Enable a private registry with given credentials for Service creation | ||
===== | ||
----- | ||
$ kn admin private-registry enable \ | ||
--secret-name=[SECRET_NAME] | ||
--docker-server=[PRIVATE_REGISTRY_SERVER_URL] \ | ||
--docker-email=[PRIVATE_REGISTRY_EMAIL] \ | ||
--docker-username=[PRIVATE_REGISTRY_USER] \ | ||
--docker-password=[PRIVATE_REGISTRY_PASSWORD] | ||
----- | ||
===== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright © 2020 The Knative Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"knative.dev/client-contrib/plugins/admin/core" | ||
) | ||
|
||
func main() { | ||
if err := core.NewAdminCommand().Execute(); err != nil { | ||
fmt.Println("failed to execute admin command:", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright © 2020 The Knative Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package core | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/mitchellh/go-homedir" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"knative.dev/client-contrib/plugins/admin/pkg" | ||
"knative.dev/client-contrib/plugins/admin/pkg/command" | ||
"knative.dev/client-contrib/plugins/admin/pkg/command/domain" | ||
private_registry "knative.dev/client-contrib/plugins/admin/pkg/command/registry" | ||
) | ||
|
||
var cfgFile string | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
|
||
func NewAdminCommand(params ...pkg.AdminParams) *cobra.Command { | ||
p := &pkg.AdminParams{} | ||
kubeConfig := os.Getenv("KUBECONFIG") | ||
if kubeConfig == "" { | ||
fmt.Println("cannot get cluster kube config, please export environment variable KUBECONFIG") | ||
os.Exit(1) | ||
} | ||
|
||
cfg, err := clientcmd.BuildConfigFromFlags("", kubeConfig) | ||
if err != nil { | ||
fmt.Println("failed to build config:", err) | ||
os.Exit(1) | ||
} | ||
|
||
p.ClientSet, err = kubernetes.NewForConfig(cfg) | ||
if err != nil { | ||
fmt.Println("failed to create client:", err) | ||
os.Exit(1) | ||
} | ||
|
||
rootCmd := &cobra.Command{ | ||
Use: "kn\u00A0admin", | ||
Short: "A plugin of kn client to manage Knative", | ||
Long: `kn admin: a plugin of kn client to manage Knative for administrators. | ||
|
||
For example: | ||
kn admin domain set - to set Knative route domain | ||
kn admin registry add - to add registry with credentials | ||
`, | ||
} | ||
cobra.OnInitialize(initConfig) | ||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/kn/plugins/admin.yaml)") | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
// | ||
rootCmd.AddCommand(domain.NewDomainCmd(p)) | ||
rootCmd.AddCommand(private_registry.NewPrivateRegistryCmd(p)) | ||
rootCmd.AddCommand(command.NewVersionCommand()) | ||
return rootCmd | ||
} | ||
|
||
// initConfig reads in config file and ENV variables if set. | ||
func initConfig() { | ||
if cfgFile != "" { | ||
// Use config file from the flag. | ||
viper.SetConfigFile(cfgFile) | ||
} else { | ||
// Find home directory. | ||
home, err := homedir.Dir() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
// Search config in home directory with name ".admin" (without extension). | ||
viper.AddConfigPath(home) | ||
viper.SetConfigName(".admin") | ||
} | ||
|
||
viper.AutomaticEnv() // read in environment variables that match | ||
|
||
// If a config file is found, read it in. | ||
if err := viper.ReadInConfig(); err == nil { | ||
fmt.Println("Using config file:", viper.ConfigFileUsed()) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module knative.dev/client-contrib/plugins/admin | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/google/go-cmp v0.3.1 // indirect | ||
github.com/googleapis/gnostic v0.2.2 // indirect | ||
github.com/imdario/mergo v0.3.8 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 | ||
github.com/pkg/errors v0.8.1 // indirect | ||
github.com/spf13/cobra v0.0.5 | ||
github.com/spf13/viper v1.6.2 | ||
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect | ||
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect | ||
google.golang.org/appengine v1.6.2 // indirect | ||
gotest.tools v2.2.0+incompatible | ||
k8s.io/api v0.17.3 | ||
k8s.io/apimachinery v0.17.3 | ||
k8s.io/client-go v0.17.0 | ||
k8s.io/utils v0.0.0-20200124190032-861946025e34 // indirect | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wonder whether we could add a OWNERS fils within the
plugins/admin
directory ? I think this would be nice as it highlights the responsibilities and point-of-contact better.I think prow supports this, let me check ...
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.
Sounds good to me. Thanks a lot and I've joined Knative org.