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

operator watches on placementrules to generate the sa/role/binding/ku… #36

Merged
merged 8 commits into from
May 16, 2020
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
3 changes: 3 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ ENV OPERATOR=/usr/local/bin/multicluster-monitoring-operator \
# install templates
COPY manifests /usr/local/manifests

# install templates for endpoint metrics operator
COPY endpoint-metrics-operator-template /usr/local/endpoint-metrics-operator-template

# install operator binary
COPY build/_output/bin/multicluster-monitoring-operator ${OPERATOR}

Expand Down
27 changes: 22 additions & 5 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"errors"
"flag"
"fmt"
"os"
"runtime"

observatoriumAPIs "github.com/observatorium/configuration/api/v1alpha1"
placementv1 "github.com/open-cluster-management/multicloud-operators-placementrule/pkg/apis/apps/v1"
ocinfrav1 "github.com/openshift/api/config/v1"
routev1 "github.com/openshift/api/route/v1"
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
kubemetrics "github.com/operator-framework/operator-sdk/pkg/kube-metrics"
Expand All @@ -21,13 +21,15 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"os"
"runtime"
"sigs.k8s.io/controller-runtime/pkg/client/config"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/scheme"

workv1 "github.com/open-cluster-management/api/work/v1"
"github.com/open-cluster-management/multicluster-monitoring-operator/pkg/apis"
"github.com/open-cluster-management/multicluster-monitoring-operator/pkg/controller"
"github.com/open-cluster-management/multicluster-monitoring-operator/version"
Expand Down Expand Up @@ -93,9 +95,10 @@ func main() {
}

// Create a new Cmd to provide shared dependencies and start components
namespaces := []string{namespace, "openshift-monitoring"}
//namespaces := []string{namespace, "openshift-monitoring"}
mgr, err := manager.New(cfg, manager.Options{
NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
//NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
Namespace: "",
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
})
if err != nil {
Expand All @@ -117,6 +120,20 @@ func main() {
os.Exit(1)
}

if err := ocinfrav1.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}

if err := workv1.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}

if err := placementv1.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}
// Setup Scheme for observatorium resources
schemeBuilder := &scheme.Builder{
GroupVersion: schema.GroupVersion{
Expand Down
21 changes: 21 additions & 0 deletions deploy/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,24 @@ rules:
- deletecollection
- watch
- create
- apiGroups:
- apps.open-cluster-management.io
resources:
- '*'
- placementrules
verbs:
- '*'
- apiGroups:
- work.open-cluster-management.io
resources:
- '*'
- manifestworks
verbs:
- '*'
- apiGroups:
- config.openshift.io
resources:
- '*'
- infrastructures
verbs:
- '*'
5 changes: 5 additions & 0 deletions endpoint-metrics-operator-template/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resources:
- role.yaml
- role_binding.yaml
- operator.yaml
- service_account.yaml
33 changes: 33 additions & 0 deletions endpoint-metrics-operator-template/operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: endpoint-metrics-operator
spec:
replicas: 1
selector:
matchLabels:
name: endpoint-metrics-operator
template:
metadata:
labels:
name: endpoint-metrics-operator
spec:
serviceAccountName: endpoint-metrics-operator
containers:
- name: endpoint-metrics-operator
# Replace this with the built image name
image: REPLACE_IMAGE
command:
- endpoint-metrics-operator
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "endpoint-metrics-operator"
80 changes: 80 additions & 0 deletions endpoint-metrics-operator-template/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: endpoint-metrics-operator
rules:
- apiGroups:
- ""
resources:
- pods
- services
- services/finalizers
- endpoints
- persistentvolumeclaims
- events
- configmaps
- secrets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- get
- create
- apiGroups:
- apps
resourceNames:
- endpoint-metrics-operator
resources:
- deployments/finalizers
verbs:
- update
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- replicasets
- deployments
verbs:
- get
- apiGroups:
- monitoring.open-cluster-management.io
resources:
- '*'
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
12 changes: 12 additions & 0 deletions endpoint-metrics-operator-template/role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: endpoint-metrics-operator
subjects:
- kind: ServiceAccount
name: endpoint-metrics-operator
namespace: acm-monitoring
roleRef:
kind: ClusterRole
name: endpoint-metrics-operator
apiGroup: rbac.authorization.k8s.io
4 changes: 4 additions & 0 deletions endpoint-metrics-operator-template/service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: endpoint-metrics-operator
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.9
github.com/observatorium/configuration v0.0.0-20200505130827-23ee12780d4c
github.com/open-cluster-management/api v0.0.0-20200512175145-bed9ce79e17e
github.com/open-cluster-management/multicloud-operators-placementrule v1.0.0-2020-05-08-20-30-09
github.com/openshift/api v3.9.1-0.20190924102528-32369d4db2ad+incompatible
github.com/openshift/client-go v0.0.0-20200116152001-92a2713fa240
github.com/openshift/cluster-monitoring-operator v0.1.1-0.20200406225945-844f960a2a8d
Expand Down
Loading