Skip to content

Commit 2310eea

Browse files
committed
Initial operator stubs
Signed-off-by: Ashok Pon Kumar <[email protected]>
1 parent cfc9912 commit 2310eea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+653
-9
lines changed

.dockerignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright IBM Corporation 2020
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
Dockerfile
16+
deploy
17+
.git
18+
.gitignore
19+

Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Build the manager binary
2+
FROM quay.io/operator-framework/helm-operator:v1.0.1
3+
4+
ENV HOME=/opt/helm
5+
COPY watches.yaml ${HOME}/watches.yaml
6+
COPY helm-charts ${HOME}/helm-charts
7+
WORKDIR ${HOME}

Makefile

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Copyright IBM Corporation 2020
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
REGISTRYNS := quay.io/konveyor
16+
17+
ifdef VERSION
18+
BINARY_VERSION = $(VERSION)
19+
endif
20+
BINARY_VERSION ?= ${GIT_TAG}
21+
ifneq ($(BINARY_VERSION),)
22+
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.version=${BINARY_VERSION}
23+
VERSION ?= $(BINARY_VERSION)
24+
endif
25+
VERSION ?= latest
26+
27+
# Default bundle image tag
28+
BUNDLE_IMG ?= controller-bundle:$(VERSION)
29+
# Options for 'bundle-build'
30+
ifneq ($(origin CHANNELS), undefined)
31+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
32+
endif
33+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
34+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
35+
endif
36+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
37+
38+
GIT_COMMIT = $(shell git rev-parse HEAD)
39+
GIT_SHA = $(shell git rev-parse --short HEAD)
40+
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
41+
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
42+
43+
# Image URL to use all building/pushing image targets
44+
IMG ?= quay.io/konveyor/move2kube-operator:latest
45+
46+
# HELP
47+
# This will output the help for each task
48+
.PHONY: help
49+
help: ## This help.
50+
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
51+
52+
all: docker-build
53+
54+
# Run against the configured Kubernetes cluster in ~/.kube/config
55+
run: helm-operator
56+
$(HELM_OPERATOR) run
57+
58+
# Install CRDs into a cluster
59+
install: kustomize
60+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
61+
62+
# Uninstall CRDs from a cluster
63+
uninstall: kustomize
64+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
65+
66+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
67+
deploy: kustomize
68+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
69+
$(KUSTOMIZE) build config/default | kubectl apply -f -
70+
71+
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
72+
undeploy: kustomize
73+
$(KUSTOMIZE) build config/default | kubectl delete -f -
74+
75+
# Build the docker image
76+
docker-build:
77+
docker build . -t ${IMG}
78+
79+
# Push the docker image
80+
docker-push:
81+
docker push ${IMG}
82+
83+
PATH := $(PATH):$(PWD)/bin
84+
SHELL := env PATH=$(PATH) /bin/sh
85+
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
86+
ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
87+
OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/')
88+
ARCHOPER = $(shell uname -m )
89+
90+
kustomize:
91+
ifeq (, $(shell which kustomize 2>/dev/null))
92+
@{ \
93+
set -e ;\
94+
mkdir -p bin ;\
95+
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | tar xzf - -C bin/ ;\
96+
}
97+
KUSTOMIZE=$(realpath ./bin/kustomize)
98+
else
99+
KUSTOMIZE=$(shell which kustomize)
100+
endif
101+
102+
helm-operator:
103+
ifeq (, $(shell which helm-operator 2>/dev/null))
104+
@{ \
105+
set -e ;\
106+
mkdir -p bin ;\
107+
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.0.1/helm-operator-v1.0.1-$(ARCHOPER)-$(OSOPER) ;\
108+
mv helm-operator-v1.0.1-$(ARCHOPER)-$(OSOPER) ./bin/helm-operator ;\
109+
chmod +x ./bin/helm-operator ;\
110+
}
111+
HELM_OPERATOR=$(realpath ./bin/helm-operator)
112+
else
113+
HELM_OPERATOR=$(shell which helm-operator)
114+
endif
115+
116+
# Generate bundle manifests and metadata, then validate generated files.
117+
.PHONY: bundle
118+
bundle: kustomize
119+
operator-sdk generate kustomize manifests -q
120+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
121+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
122+
operator-sdk bundle validate ./bundle
123+
124+
# Build the bundle image.
125+
.PHONY: bundle-build
126+
bundle-build:
127+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

PROJECT

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
domain: io
2+
layout: helm.sdk.operatorframework.io/v1
3+
projectName: move2kube-operator
4+
resources:
5+
- group: konveyor.openshift
6+
kind: Move2Kube
7+
version: v1alpha1
8+
version: 3-alpha

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# move2kube-operator
1+
# Move2Kube-Operator
2+
23
Operator to orchestrate Move2Kube UI and API
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: move2kubes.charts.io
6+
spec:
7+
group: charts.io
8+
names:
9+
kind: Move2Kube
10+
listKind: Move2KubeList
11+
plural: move2kubes
12+
singular: move2kube
13+
scope: Namespaced
14+
versions:
15+
- name: v1alpha1
16+
schema:
17+
openAPIV3Schema:
18+
description: Move2Kube is the Schema for the move2kubes API
19+
properties:
20+
apiVersion:
21+
description: 'APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this
27+
object represents. Servers may infer this from the endpoint the client
28+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: Spec defines the desired state of Move2Kube
34+
type: object
35+
x-kubernetes-preserve-unknown-fields: true
36+
status:
37+
description: Status defines the observed state of Move2Kube
38+
type: object
39+
x-kubernetes-preserve-unknown-fields: true
40+
type: object
41+
served: true
42+
storage: true
43+
subresources:
44+
status: {}

config/crd/kustomization.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This kustomization.yaml is not intended to be run by itself,
2+
# since it depends on service name and namespace that are out of this kustomize package.
3+
# It should be run by config/default
4+
resources:
5+
- bases/charts.io_move2kubes.yaml
6+
# +kubebuilder:scaffold:crdkustomizeresource

config/default/kustomization.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Adds namespace to all resources.
2+
namespace: move2kube-operator-system
3+
4+
# Value of this field is prepended to the
5+
# names of all resources, e.g. a deployment named
6+
# "wordpress" becomes "alices-wordpress".
7+
# Note that it should also match with the prefix (text before '-') of the namespace
8+
# field above.
9+
namePrefix: move2kube-operator-
10+
11+
# Labels to add to all resources and selectors.
12+
#commonLabels:
13+
# someName: someValue
14+
15+
bases:
16+
- ../crd
17+
- ../rbac
18+
- ../manager
19+
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
20+
#- ../prometheus
21+
22+
patchesStrategicMerge:
23+
# Protect the /metrics endpoint by putting it behind auth.
24+
# If you want your controller-manager to expose the /metrics
25+
# endpoint w/o any authn/z, please comment the following line.
26+
- manager_auth_proxy_patch.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This patch inject a sidecar container which is a HTTP proxy for the
2+
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: controller-manager
7+
namespace: system
8+
spec:
9+
template:
10+
spec:
11+
containers:
12+
- name: kube-rbac-proxy
13+
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
14+
args:
15+
- "--secure-listen-address=0.0.0.0:8443"
16+
- "--upstream=http://127.0.0.1:8080/"
17+
- "--logtostderr=true"
18+
- "--v=10"
19+
ports:
20+
- containerPort: 8443
21+
name: https
22+
- name: manager
23+
args:
24+
- "--metrics-addr=127.0.0.1:8080"
25+
- "--enable-leader-election"
26+
- "--leader-election-id=move2kube-operator"

config/manager/kustomization.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resources:
2+
- manager.yaml

config/manager/manager.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
name: system
7+
---
8+
apiVersion: apps/v1
9+
kind: Deployment
10+
metadata:
11+
name: controller-manager
12+
namespace: system
13+
labels:
14+
control-plane: controller-manager
15+
spec:
16+
selector:
17+
matchLabels:
18+
control-plane: controller-manager
19+
replicas: 1
20+
template:
21+
metadata:
22+
labels:
23+
control-plane: controller-manager
24+
spec:
25+
containers:
26+
- image: quay.io/konveyor/move2kube-operator:latest
27+
args:
28+
- "--enable-leader-election"
29+
- "--leader-election-id=move2kube-operator"
30+
name: manager
31+
resources:
32+
limits:
33+
cpu: 100m
34+
memory: 90Mi
35+
requests:
36+
cpu: 100m
37+
memory: 60Mi
38+
terminationGracePeriodSeconds: 10

config/prometheus/kustomization.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resources:
2+
- monitor.yaml

config/prometheus/monitor.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# Prometheus Monitor Service (Metrics)
3+
apiVersion: monitoring.coreos.com/v1
4+
kind: ServiceMonitor
5+
metadata:
6+
labels:
7+
control-plane: controller-manager
8+
name: controller-manager-metrics-monitor
9+
namespace: system
10+
spec:
11+
endpoints:
12+
- path: /metrics
13+
port: https
14+
selector:
15+
matchLabels:
16+
control-plane: controller-manager
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: rbac.authorization.k8s.io/v1beta1
2+
kind: ClusterRole
3+
metadata:
4+
name: metrics-reader
5+
rules:
6+
- nonResourceURLs: ["/metrics"]
7+
verbs: ["get"]

config/rbac/auth_proxy_role.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: proxy-role
5+
rules:
6+
- apiGroups: ["authentication.k8s.io"]
7+
resources:
8+
- tokenreviews
9+
verbs: ["create"]
10+
- apiGroups: ["authorization.k8s.io"]
11+
resources:
12+
- subjectaccessreviews
13+
verbs: ["create"]
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: proxy-rolebinding
5+
roleRef:
6+
apiGroup: rbac.authorization.k8s.io
7+
kind: ClusterRole
8+
name: proxy-role
9+
subjects:
10+
- kind: ServiceAccount
11+
name: default
12+
namespace: system

config/rbac/auth_proxy_service.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
name: controller-manager-metrics-service
7+
namespace: system
8+
spec:
9+
ports:
10+
- name: https
11+
port: 8443
12+
targetPort: https
13+
selector:
14+
control-plane: controller-manager

0 commit comments

Comments
 (0)