-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
operator-sdk/cmd: add up command #219
operator-sdk/cmd: add up command #219
Conversation
depends on #218 |
09bc729
to
5f5cd3c
Compare
52f101b
to
6d50689
Compare
manual test: $ operator-sdk up -h
The operator-sdk up command launches the operator on the local machine
by building the operator binary with the ability to access a
kubernetes cluster using a Kubernete config file.
Usage:
operator-sdk up [Flags] [flags]
Flags:
-h, --help help for up
--kubeconfig string The file path to kubernetes configuration file; defaults to $HOME/.kube/config
$ cat config/config.yaml
apiVersion: example.com/v1alpha1
kind: AppService
projectName: app-operator
$ pwd
/Users/fanminshi/work/src/github.com/operator-framework/app-operator
fanmins-MBP:app-operator fanminshi$ operator-sdk up
INFO[0000] Go Version: go1.10
INFO[0000] Go OS/Arch: darwin/amd64
INFO[0000] operator-sdk Version: 0.0.5+git
INFO[0000] starting appservices controller |
When I see a top level command called "up" I imagine that it is to deploy my operator to a running cluster. This seems to be for local development. Is "up" the right command name here? Who is the user and what is his use case? |
Maybe we can name this command with a better name to illustrate the intended behavior. |
Maybe "up --local" ? That way "up" can be to run it inside the cluster? For dev and test it's probably valuable to be able to do both? |
I am thinking about having separate sub commands for local and cluster deployment. The reason for having separate command is that I suspect that |
let's keep the design discussion here #142 |
6d50689
to
53ddd96
Compare
53ddd96
to
81d13dd
Compare
operator-sdk CLI interface :$ operator-sdk -h
A sdk for building operator with ease
Usage:
operator-sdk [command]
Available Commands:
build Compiles code and builds artifacts
generate Invokes specific generator
help Help about any command
new Creates a new operator application
up Launches the operator
Flags:
-h, --help help for operator-sdk
Use "operator-sdk [command] --help" for more information about a command.
$ operator-sdk up -h
The up command has subcommands that can launch the operator in various ways.
Usage:
operator-sdk up [command]
Available Commands:
local Launches the operator locally
Flags:
-h, --help help for up
Use "operator-sdk up [command] --help" for more information about a command.
$ operator-sdk up local -h
The operator-sdk up local command launches the operator on the local machine
by building the operator binary with the ability to access a
kubernetes cluster using a Kubernete config file.
Usage:
operator-sdk up local [flags]
Flags:
-h, --help help for local
--kubeconfig string The file path to kubernetes configuration file; defaults to $HOME/.kube/config
$ pwd
/Users/fanminshi/work/src/github.com/operator-framework/app-operator Local Test$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 43d
$ cat deploy/crd.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: apps.app.example.com
spec:
group: app.example.com
names:
kind: App
listKind: AppList
plural: apps
singular: app
scope: Namespaced
version: v1alpha1
$ kubectl create -f deploy/crd.yaml
customresourcedefinition "apps.app.example.com" created
$ operator-sdk up local
INFO[0000] Go Version: go1.10
INFO[0000] Go OS/Arch: darwin/amd64
INFO[0000] operator-sdk Version: 0.0.5+git
INFO[0000] starting apps controller
# In a different terminal
$ kubectl create -f deploy/cr.yaml
app "example" created
$ kubectl get po
NAME READY STATUS RESTARTS AGE
busy-box 1/1 Running 0 3s |
Short: "Launches the operator locally", | ||
Long: `The operator-sdk up local command launches the operator on the local machine | ||
by building the operator binary with the ability to access a | ||
kubernetes cluster using a Kubernete config file. |
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.
using a Kubernete config file
==> using a kubeconfig file
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.
fixed!
81d13dd
to
d9babea
Compare
|
||
cmdError "github.com/operator-framework/operator-sdk/commands/operator-sdk/error" | ||
"github.com/operator-framework/operator-sdk/pkg/generator" | ||
yaml "gopkg.in/yaml.v2" |
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.
Leave a line break before this.
|
||
_, err := os.Stat(kubeConfig) | ||
if err != nil && os.IsNotExist(err) { | ||
cmdError.ExitWithError(cmdError.ExitError, fmt.Errorf("failed to fine the Kubernetes config file (%v): %v", kubeConfig, err)) |
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.
failed to fine the Kubernetes config file
==> failed to find the kubeconfig file
dc := exec.Command(gocmd, run, filepath.Join(cmd, projectName, main)) | ||
dc.Stdout = os.Stdout | ||
dc.Stderr = os.Stderr | ||
dc.Env = append(os.Environ(), fmt.Sprintf("KUBERNETES_CONFIG=%v", kubeConfig)) |
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.
Make the string KUBERNETES_CONFIG
a constant because it's common to pkg/k8sclient/client.go and here.
} | ||
} | ||
|
||
func up(projectName string) { |
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.
Can you rename this to upLocal()
. Because we'll be adding an up cluster
command in the same package later on.
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.
yeah sure!
96c24bc
to
32b397e
Compare
all fixed PTAL cc/ @hasbro17 |
65b9a18
to
7904407
Compare
7904407
to
ebc09c0
Compare
ebc09c0
to
f1ca75d
Compare
LGTM |
This pr adds a new command call
up
and its subcommandlocal
.When
operator-sdk up local
is called, the operator is run locally on developer's machine with the access to a kubernetes cluster via the--kubeconfig
flag.ref: #142
cc/ @hasbro17 @spahl