Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions examples/guestbook-operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN go mod download
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY vendor/ vendor/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
Expand Down
11 changes: 10 additions & 1 deletion examples/guestbook-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -

# Teardown controller in the configured Kubernetes cluster in ~/.kube/config
# This command does things that can't always re-run so the exit codes are ignored
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the comment here!

teardown: manifests
kustomize build config/default | kubectl delete -f - || true

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
Expand All @@ -50,12 +55,15 @@ fmt:
vet:
go vet ./...

vendor:
go mod vendor

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."

# Build the docker image
docker-build: test
docker-build: vendor test
docker build . -t ${IMG}

# Push the docker image
Expand All @@ -78,3 +86,4 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

6 changes: 6 additions & 0 deletions examples/guestbook-operator/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: controller
newTag: latest
4 changes: 1 addition & 3 deletions examples/guestbook-operator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ require (
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90
sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-00010101000000-000000000000
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-20200317144824-bbf1fb2a4a9a
)

replace sigs.k8s.io/kubebuilder-declarative-pattern => ../../
2 changes: 2 additions & 0 deletions examples/guestbook-operator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jC
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
sigs.k8s.io/controller-runtime v0.4.0 h1:wATM6/m+3w8lj8FXNaO6Fs/rq/vqoOjO1Q116Z9NPsg=
sigs.k8s.io/controller-runtime v0.4.0/go.mod h1:ApC79lpY3PHW9xj/w9pj+lYkLgwAAUZwfXkME1Lajns=
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-20200317144824-bbf1fb2a4a9a h1:UdSbADtqxVDTwICFMWXVmjPyzSn+xfaYmxjHa2jPrj0=
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-20200317144824-bbf1fb2a4a9a/go.mod h1:UmLMohI25YTEDjmGhTZ3eiE9DPEfxtbAykwZFQJ92g8=
sigs.k8s.io/kustomize/api v0.2.0 h1:e++6JpysnnlUbHmFrv6jvfF5rFlgQ103bS1DO7r5bWA=
sigs.k8s.io/kustomize/api v0.2.0/go.mod h1:zVtMg179jW1gr74jo9fc2Ac9dLYLTZZThc3DDb9lDW4=
sigs.k8s.io/kustomize/pseudo/k8s v0.1.0 h1:otg4dLFc03c3gzl+2CV8GPGcd1kk8wjXwD+UhhcCn5I=
Expand Down
25 changes: 13 additions & 12 deletions hack/smoketest.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ import (
)

const (
defaultSystemNamespace = "kube-system"
// Set default namespace for your operator.
defaultSystemNamespace = "guestbook-operator-system"
)

type (
Expand Down Expand Up @@ -125,7 +126,7 @@ func main() {

var operators []AddonTest
for _, test := range []AddonTest{
NewDashboardTest(c),
NewGuestbookTest(c),
} {
if _, ignored := ignore[test.Name()]; ignored {
log.Printf("ignoring test: %s", test.Name())
Expand Down Expand Up @@ -568,34 +569,34 @@ func (c *CommonAddonTest) VerifyDown() error {
return fmt.Errorf("VerifyDown not implemented for operator: %s", c.Name())
}

type DashboardTest struct {
type GuestbookTest struct {
CommonAddonTest
}

func NewDashboardTest(c CommonAddonTest) *DashboardTest {
t := &DashboardTest{CommonAddonTest: c}
t.Base = "../examples/dashboard-operator"
func NewGuestbookTest(c CommonAddonTest) *GuestbookTest {
t := &GuestbookTest{CommonAddonTest: c}
t.Base = "../examples/guestbook-operator"
return t
}

func (k *DashboardTest) VerifyUp() error {
func (k *GuestbookTest) VerifyUp() error {
h := k.Harness

err := verifyReadyPods(h, defaultSystemNamespace, "kubernetes-dashboard")
err := verifyReadyPods(h, defaultSystemNamespace, "guestbook-operator")
if err != nil {
return err
}

return nil
}

func (t *DashboardTest) Disrupt() {
_, err := executeCommand("kubectl", "delete", "all", "-l", "k8s-app=kubernetes-dashboard", "-n", defaultSystemNamespace)
func (t *GuestbookTest) Disrupt() {
_, err := executeCommand("kubectl", "delete", "all", "-l", "example-app=guestbook", "-n", defaultSystemNamespace)
if err != nil {
glog.Warningf("kubectl delete finished with error: %v", err)
}
}

func (k *DashboardTest) VerifyDown() error {
return verifyNoWorkloadsWithLabel("k8s-app=kubernetes-dashboard", defaultSystemNamespace)
func (k *GuestbookTest) VerifyDown() error {
return verifyNoWorkloadsWithLabel("example-app=guestbook", defaultSystemNamespace)
}