Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Restruct kn-admin plugin
Browse files Browse the repository at this point in the history
- To align with hello example plugin, restruct and add missing part
- Add admin plugin maintainer in OWNERS
  • Loading branch information
Gong Zhang committed Apr 19, 2020
1 parent b01f0ad commit 47f710a
Show file tree
Hide file tree
Showing 1,772 changed files with 34,257 additions and 3,011 deletions.
1 change: 1 addition & 0 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ approvers:
- rhuss
- maximilien
- navidshaikh
- zhanggbj
# TOC members as a fallback
- mattmoor
- evankanderson
14 changes: 0 additions & 14 deletions go.mod

This file was deleted.

Binary file added kn-admin
Binary file not shown.
124 changes: 124 additions & 0 deletions plugins/admin/README.adoc
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.

### 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.
For example:
kn admin domain set - to set Knative route domain
kn admin private-registry enable - to enable deployment from the private registry
Usage:
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]
Usage:
kn admin private-registry [command]
Available Commands:
enable enable Service deployment from a private registry
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]
-----
=====
28 changes: 28 additions & 0 deletions plugins/admin/cmd/kn-admin.go
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)
}
}
59 changes: 30 additions & 29 deletions plugins/kn-admin/core/root.go → plugins/admin/core/root.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
/*
Copyright © 2019 NAME HERE <EMAIL ADDRESS>
// 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.

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"
"github.com/knative/client-contrib/plugins/kn-admin/cmd"
"github.com/knative/client-contrib/plugins/kn-admin/cmd/domain"
private_registry "github.com/knative/client-contrib/plugins/kn-admin/cmd/private-registry"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"os"

homedir "github.com/mitchellh/go-homedir"
"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 ...cmd.AdminParams) *cobra.Command {
p := &cmd.AdminParams{}
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")
Expand All @@ -54,21 +54,22 @@ func NewAdminCommand(params ...cmd.AdminParams) *cobra.Command {
}

rootCmd := &cobra.Command{
Use: "admin",
Use: "kn\u00A0admin",
Short: "A plugin of kn client to manage Knative",
Long: `A plugin of kn client to manage Knative for administrators.
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 private-registry enable - to enable deployment from the private registry
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/kn-admin.yaml)")
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
}

Expand All @@ -85,9 +86,9 @@ func initConfig() {
os.Exit(1)
}

// Search config in home directory with name ".kn-admin" (without extension).
// Search config in home directory with name ".admin" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".kn-admin")
viper.SetConfigName(".admin")
}

viper.AutomaticEnv() // read in environment variables that match
Expand Down
21 changes: 21 additions & 0 deletions plugins/admin/go.mod
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
)
Loading

0 comments on commit 47f710a

Please sign in to comment.