Skip to content
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

[WIP] console-operator based on client-go #2

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
432ab80
Renamed all occurance of "example" to "console". Regenerate pkg/gener…
benjaminapetersen Nov 7, 2018
4053c8f
Update manifests to match existing console-operator manifests
benjaminapetersen Nov 7, 2018
0211c3f
Update Dockerfile & create Dockerfile.osx for local
benjaminapetersen Nov 7, 2018
dde0e00
Adding back examples/config.yaml as this will likely be needed
benjaminapetersen Nov 7, 2018
a1dd54d
Update README to include expected flags & build/run process
benjaminapetersen Nov 7, 2018
030787e
Add `console version` command
benjaminapetersen Nov 7, 2018
e49a054
Add some dev_*.sh scripts
benjaminapetersen Nov 7, 2018
1012bf3
Update README
benjaminapetersen Nov 8, 2018
848530d
Add dev_delete_all.sh hack script
benjaminapetersen Nov 8, 2018
b778e5d
Comment on dev_run_local.sh
benjaminapetersen Nov 8, 2018
c3eb95c
Add todo to version command
benjaminapetersen Nov 8, 2018
45e1fb3
Add comment to cmd/operator/cmd.go
benjaminapetersen Nov 8, 2018
ab8a721
Update dev_run_local.sh (f)
benjaminapetersen Nov 8, 2018
51e05a1
Create ClusterOperatorStatus in starter.go
benjaminapetersen Nov 8, 2018
1c0cbc7
Add all clients, informers to starter, operator
benjaminapetersen Nov 9, 2018
4b93caf
Create default console if CR does not exist
benjaminapetersen Nov 15, 2018
563299b
Update sync loop, add Apply for all subresources
benjaminapetersen Nov 16, 2018
ff8d7e4
Add dev_* scripts for convenience
benjaminapetersen Nov 19, 2018
584f8ad
Add TODO to types.go to describe future custom host work
benjaminapetersen Nov 19, 2018
efb8e65
Update sync loop, tmp remove OwnerRef
benjaminapetersen Nov 19, 2018
4b3f802
Return to functioning reconcile loop
benjaminapetersen Nov 20, 2018
d4a81c9
Handle ManagementState: Removed, refactor 'Default' resource function…
benjaminapetersen Nov 20, 2018
e1d6052
Clean up excessive comments
benjaminapetersen Nov 20, 2018
d59d60c
f
benjaminapetersen Nov 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# This is an example operator.
#
# The standard name for its image is enj/example-operator
#
FROM openshift/origin-release:golang-1.10
COPY . /go/src/github.com/enj/example-operator
RUN cd /go/src/github.com/enj/example-operator && go build ./cmd/example
FROM openshift/origin-release:golang-1.10 as builder
WORKDIR /go/src/github.com/openshift/console-operator
COPY . .
RUN make build

FROM centos:7
COPY --from=0 /go/src/github.com/enj/example-operator/example /usr/bin/example
RUN useradd console-operator
USER console-operator
COPY --from=builder /go/src/github.com/openshift/console-operator/_output/local/bin/linux/amd64/console /usr/bin

# these manifests are necessary for the installer
COPY manifests /manifests/

LABEL io.k8s.display-name="OpenShift console-operator" \
io.k8s.description="This is a component of OpenShift Container Platform and manages the lifecycle of the web console." \
io.openshift.tags="openshift" \
maintainer="Benjamin A. Petersen <bpetersen@redhat.com>"

LABEL io.openshift.release.operator true

# entrypoint specified in 03-operator.yaml as `console-operator`
# CMD ["/usr/bin/console", "operator", "--kubeconfig", "path/to/config", "--config", "./install/config.yaml", "--v", "4"]
CMD ["/usr/bin/console", "operator", "--v", "4"]


27 changes: 27 additions & 0 deletions Dockerfile.osx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM openshift/origin-release:golang-1.10 as builder
WORKDIR /go/src/github.com/openshift/console-operator
COPY . .
RUN make build

FROM centos:7
RUN useradd console-operator
USER console-operator
COPY --from=builder /go/src/github.com/openshift/console-operator/_output/local/bin/darwin/amd64/console /usr/bin

# these manifests are necessary for the installer
COPY manifests /manifests/

LABEL io.k8s.display-name="OpenShift console-operator" \
io.k8s.description="This is a component of OpenShift Container Platform and manages the lifecycle of the web console." \
io.openshift.tags="openshift" \
maintainer="Benjamin A. Petersen <bpetersen@redhat.com>"

LABEL io.openshift.release.operator true

# entrypoint specified in 03-operator.yaml as `console-operator`
# CMD ["/usr/bin/console", "operator", "--kubeconfig", "path/to/config", "--config", "./install/config.yaml", "--v", "4"]
CMD ["/usr/bin/console", "operator", "--v", "4"]




87 changes: 77 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,84 @@
# Example Operator
# Console Operator

```shell
cd "${GOPATH}/src/github.com/enj/example-operator"
An operator for OpenShift Console built using the operator-sdk.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


oc new-project example-operator
The console-operator installs and maintains the web console on a cluster.

oc create -f manifests/00-crd.yaml
oc create -f install/cr.yaml
## Run on a 4.0.0 cluster

The console operator is installed by default and will automatically maintain a console.

## Development Setup

* Install Go -- https://golang.org/doc/install

## Development on a < 4.0.0 cluster

If using `oc cluster up` on a `< 4.0.0` cluster you will need the `--public-hostname` flag
when you cluster up. The `--server-loglevel` flag is helpful for debugging. OAuth issues
will not be visible unless set to at least `3`.

```bash
# there are a variety of ways to get your machine IP address
# this example works on OSX
oc cluster up --public-hostname=$(ipconfig getifaddr en0) --server-loglevel 3
```

Then, create the manifests:

```bash
# pre 4.0.0 needs this, but it is not part of the post 4.0.0 manifests payload
oc create -f ./examples/crd-clusteroperator.yaml
# standard 4.0.0 deploy of the operator
oc create -f ./manifests
# to run the operator locally, delete the deployment and follow instructions below
oc delete -f ./manifests/05-operator.yaml
```

If you don't know where your `kubeconfig` file is:

```bash
# just a high number
oc whoami --loglevel=100
# likely output will be $HOME/.kube/config
```

Build the console operator binary:

```bash
make update-codegen
make
export PATH="_output/local/bin/linux/amd64:${PATH}"
example operator --kubeconfig admin.kubeconfig --config install/config.yaml --v=4
make verify
# add the binary to your path
# arc will be "linux" or "darwin", etc
export PATH="_output/local/bin/<arc>/amd64:${PATH}"
```

Now, run the console operator locally:

```bash
IMAGE=docker.io/openshift/origin-console:latest \
console operator \
--kubeconfig $HOME/.kube/config \
--config examples/config.yaml \
--create-default-console \
--v 4
```

oc get exampleoperator example-operator-resource -o yaml
oc get secret example-operator-resource -o yaml
Check for the existence of expected resources:

```bash
oc get console
# etc
```


Explanation:

- The `IMAGE` env var is needed to declare what console image to deploy. The `manifests/05-operator.yaml` shows this var as well
- The `--operator-flags` flag is used to pass flags to the operator binary
- `--create-default-console true` tells the operator binary to create a console CR if one does not exist on startup.

The `IMAGE` env var exists so that when the console-operator is packaged up for a release, we can replace the value
with a final image. See CVO documentation for details.

27 changes: 19 additions & 8 deletions cmd/example/main.go → cmd/console/main.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
package main

import (
// standard lib
goflag "flag"
"fmt"
"math/rand"
"os"
"time"

// 3rd party
"github.com/spf13/cobra"
"github.com/spf13/pflag"

// kube / openshift
utilflag "k8s.io/apiserver/pkg/util/flag"
"k8s.io/apiserver/pkg/util/logs"

"github.com/enj/example-operator/pkg/cmd/operator"
// us
"github.com/openshift/console-operator/pkg/cmd/operator"
"github.com/openshift/console-operator/pkg/cmd/version"
)

func main() {
// random seed, set it & forget it
rand.Seed(time.Now().UTC().UnixNano())

// normalize flags, if _ use -
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
// add the default flag set for go
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)

logs.InitLogs()
defer logs.FlushLogs()

command := NewExampleCommand()
// build a new cobra command
command := NewOperatorCommand()
// die on errors
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}

func NewExampleCommand() *cobra.Command {
// create the root "console" command
// we will add subcommands to this
func NewOperatorCommand() *cobra.Command {
// "console" just prints help, then exists. It doesn't start
// the operator.
cmd := &cobra.Command{
Use: "example",
Use: "console",
Short: "Top level command",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
Expand All @@ -43,6 +53,7 @@ func NewExampleCommand() *cobra.Command {
}

cmd.AddCommand(operator.NewOperator())
cmd.AddCommand(version.NewVersion())

return cmd
}
49 changes: 49 additions & 0 deletions dev_delete_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# this just deletes everything under /manifests,
# but tries to space them out a bit to avoid errors.
# in the end, it creates a custom resource to kick
# the operator into action

FILE=examples/cr.yaml
echo "creating ${FILE}"
oc create -f $FILE
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick copy paste, haven't tested that one yet.
obviously :)


for FILE in `find ./manifests -name '05-*'`
do
echo "deleting ${FILE}"
oc create -f $FILE
done

for FILE in `find ./manifests -name '04-*'`
do
echo "deleting ${FILE}"
oc create -f $FILE
done

for FILE in `find ./manifests -name '03-*'`
do
echo "deleting ${FILE}"
oc create -f $FILE
done

for FILE in `find ./manifests -name '02-*'`
do
echo "deleting ${FILE}"
oc create -f $FILE
done

for FILE in `find ./manifests -name '01-*'`
do
echo "deleting ${FILE}"
oc create -f $FILE
done

for FILE in `find ./manifests -name '00-*'`
do
echo "deleting ${FILE}"
oc create -f $FILE
done



59 changes: 59 additions & 0 deletions dev_deploy_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

# this just deploys everything under /manifests,
# but tries to space them out a bit to avoid errors.
# in the end, it creates a custom resource to kick
# the operator into action

for FILE in `find ./manifests -name '00-*'`
do
echo "creating ${FILE}"
oc create -f $FILE
done

sleep 2

for FILE in `find ./manifests -name '01-*'`
do
echo "creating ${FILE}"
oc create -f $FILE
done

sleep 2

for FILE in `find ./manifests -name '02-*'`
do
echo "creating ${FILE}"
oc create -f $FILE
done

sleep 2

for FILE in `find ./manifests -name '03-*'`
do
echo "creating ${FILE}"
oc create -f $FILE
done

sleep 2

for FILE in `find ./manifests -name '04-*'`
do
echo "creating ${FILE}"
oc create -f $FILE
done

sleep 2

for FILE in `find ./manifests -name '05-*'`
do
echo "creating ${FILE}"
oc create -f $FILE
done

sleep 2


FILE=examples/cr.yaml
echo "creating ${FILE}"
oc create -f $FILE
Loading