From e06b947b03c3fcce2c954feb68890a519c7740c3 Mon Sep 17 00:00:00 2001 From: Eric Multanen Date: Wed, 1 Jul 2020 23:30:49 -0700 Subject: Adds composite app status update and query This patch provides the basic framework for supporting monitoring of composite application resources in clusters. 1. Updates to the monitor files for use with v2. 2. Invokes the Watcher process per cluster/app when the app is instantiated. 3. Adds a ResourceBundleState CR resource to the cluster/app so that monitor will be able to update status to it. 4. Watcher updates appropriate appcontext status object when updates are made in clusters by monitor 5. Update appcontext library to define a status handle and object at the app/cluster level 6. Labels resources with an appropriate tracking label to coordinate with the ResourceBundleState CR Issue-ID: MULTICLOUD-1042 Signed-off-by: Eric Multanen Change-Id: If007c1fd86ca7a65bb941d1776cfd2d3afed766b --- src/monitor/build/Dockerfile | 21 +++---- src/monitor/deploy/cluster_role.yaml | 72 ++++++++++++++++++++++++ src/monitor/deploy/clusterrole_binding.yaml | 12 ++++ src/monitor/deploy/monitor-cleanup.sh | 6 ++ src/monitor/deploy/monitor-deploy.sh | 6 ++ src/monitor/deploy/operator.yaml | 14 ++--- src/monitor/deploy/role.yaml | 12 ++++ src/monitor/go.mod | 2 - src/monitor/pkg/apis/k8splugin/v1alpha1/types.go | 4 +- 9 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 src/monitor/deploy/cluster_role.yaml create mode 100644 src/monitor/deploy/clusterrole_binding.yaml create mode 100755 src/monitor/deploy/monitor-cleanup.sh create mode 100755 src/monitor/deploy/monitor-deploy.sh (limited to 'src/monitor') diff --git a/src/monitor/build/Dockerfile b/src/monitor/build/Dockerfile index 812eb47e..9ecff169 100644 --- a/src/monitor/build/Dockerfile +++ b/src/monitor/build/Dockerfile @@ -1,15 +1,16 @@ -FROM registry.access.redhat.com/ubi7/ubi-minimal:latest +FROM golang:1.14.1 -ENV OPERATOR=/usr/local/bin/monitor \ - USER_UID=1001 \ - USER_NAME=monitor +WORKDIR /go/src/github.com/onap/multicloud-k8s/src/monitor +COPY ./ ./ +RUN make all -# install operator binary -COPY _output/bin/monitor ${OPERATOR} +FROM ubuntu:16.04 -COPY bin /usr/local/bin -RUN /usr/local/bin/user_setup +WORKDIR /opt/monitor +RUN groupadd -r monitor && useradd -r -g monitor monitor +RUN chown monitor:monitor /opt/monitor -R +COPY --chown=monitor --from=0 /go/src/github.com/onap/multicloud-k8s/src/monitor/monitor ./ -ENTRYPOINT ["/usr/local/bin/entrypoint"] +USER monitor +ENTRYPOINT ["/opt/monitor/monitor"] -USER ${USER_UID} diff --git a/src/monitor/deploy/cluster_role.yaml b/src/monitor/deploy/cluster_role.yaml new file mode 100644 index 00000000..0732e8d3 --- /dev/null +++ b/src/monitor/deploy/cluster_role.yaml @@ -0,0 +1,72 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + creationTimestamp: null + name: monitor +rules: +- apiGroups: + - "" + resources: + - pods + - services + - endpoints + - persistentvolumeclaims + - events + - configmaps + - secrets + verbs: + - '*' +- apiGroups: + - apps + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + verbs: + - '*' +- apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + verbs: + - get + - create +- apiGroups: + - apps + resourceNames: + - monitor + resources: + - deployments/finalizers + verbs: + - update +- apiGroups: + - "" + resources: + - pods + verbs: + - get +- apiGroups: + - apps + resources: + - replicasets + verbs: + - get +- apiGroups: + - k8splugin.io + resources: + - '*' + verbs: + - '*' +- apiGroups: + - batch + resources: + - '*' + verbs: + - '*' +- apiGroups: + - extensions + resources: + - '*' + verbs: + - '*' diff --git a/src/monitor/deploy/clusterrole_binding.yaml b/src/monitor/deploy/clusterrole_binding.yaml new file mode 100644 index 00000000..73e74039 --- /dev/null +++ b/src/monitor/deploy/clusterrole_binding.yaml @@ -0,0 +1,12 @@ +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: monitor +subjects: +- kind: ServiceAccount + name: monitor + namespace: default +roleRef: + kind: ClusterRole + name: monitor + apiGroup: rbac.authorization.k8s.io diff --git a/src/monitor/deploy/monitor-cleanup.sh b/src/monitor/deploy/monitor-cleanup.sh new file mode 100755 index 00000000..21725073 --- /dev/null +++ b/src/monitor/deploy/monitor-cleanup.sh @@ -0,0 +1,6 @@ +kubectl delete rolebinding monitor +kubectl delete clusterrolebinding monitor +kubectl delete role monitor +kubectl delete clusterrole monitor +kubectl delete serviceaccount monitor +kubectl delete deploy monitor diff --git a/src/monitor/deploy/monitor-deploy.sh b/src/monitor/deploy/monitor-deploy.sh new file mode 100755 index 00000000..47c7120f --- /dev/null +++ b/src/monitor/deploy/monitor-deploy.sh @@ -0,0 +1,6 @@ +kubectl apply -f role.yaml +kubectl apply -f cluster_role.yaml +kubectl apply -f role_binding.yaml +kubectl apply -f clusterrole_binding.yaml +kubectl apply -f service_account.yaml +kubectl apply -f operator.yaml diff --git a/src/monitor/deploy/operator.yaml b/src/monitor/deploy/operator.yaml index a06c07d3..93e4522c 100644 --- a/src/monitor/deploy/operator.yaml +++ b/src/monitor/deploy/operator.yaml @@ -3,30 +3,28 @@ kind: Deployment metadata: name: monitor labels: - "emco/deployment-id": "bionic-beaver" + "emco/deployment-id": "monitor" spec: replicas: 1 selector: matchLabels: - "emco/deployment-id": "bionic-beaver" + "emco/deployment-id": "monitor" template: metadata: labels: - "emco/deployment-id": "bionic-beaver" + "emco/deployment-id": "monitor" spec: serviceAccountName: monitor containers: - name: monitor # Replace this with the built image name - image: k8splugin.io/monitor:latest + image: ewmduck/monitor:latest command: - - monitor + - /opt/monitor/monitor imagePullPolicy: IfNotPresent env: - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace + value: "" - name: POD_NAME valueFrom: fieldRef: diff --git a/src/monitor/deploy/role.yaml b/src/monitor/deploy/role.yaml index 4d0fd1b6..c48141ac 100644 --- a/src/monitor/deploy/role.yaml +++ b/src/monitor/deploy/role.yaml @@ -58,3 +58,15 @@ rules: - '*' verbs: - '*' +- apiGroups: + - batch + resources: + - '*' + verbs: + - '*' +- apiGroups: + - extensions + resources: + - '*' + verbs: + - '*' diff --git a/src/monitor/go.mod b/src/monitor/go.mod index ec48d268..6eff59af 100644 --- a/src/monitor/go.mod +++ b/src/monitor/go.mod @@ -32,6 +32,4 @@ replace ( sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde ) -// Remove hg dependency using this mirror replace github.com/operator-framework/operator-sdk => github.com/operator-framework/operator-sdk v0.9.0 - diff --git a/src/monitor/pkg/apis/k8splugin/v1alpha1/types.go b/src/monitor/pkg/apis/k8splugin/v1alpha1/types.go index 231f226e..064591fc 100644 --- a/src/monitor/pkg/apis/k8splugin/v1alpha1/types.go +++ b/src/monitor/pkg/apis/k8splugin/v1alpha1/types.go @@ -15,8 +15,8 @@ import ( // +kubebuilder:subresource:status // +genclient type ResourceBundleState struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + metav1.TypeMeta `json:",inline" yaml:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata" yaml:"metadata"` Spec ResourceBundleStateSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` Status ResourceBundleStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` -- cgit 1.2.3-korg