Skip to content

Commit

Permalink
Fix apache#1450: fix servicemonitor roles on direct install
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed May 6, 2020
1 parent f043c29 commit 0b18732
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
30 changes: 30 additions & 0 deletions deploy/operator-role-binding-servicemonitors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: camel-k-operator-servicemonitors
labels:
app: "camel-k"
subjects:
- kind: ServiceAccount
name: camel-k-operator
roleRef:
kind: Role
name: camel-k-operator-servicemonitors
apiGroup: rbac.authorization.k8s.io
37 changes: 37 additions & 0 deletions deploy/operator-role-servicemonitors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: camel-k-operator-servicemonitors
labels:
app: "camel-k"
rules:
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
16 changes: 16 additions & 0 deletions deploy/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions pkg/install/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfigu
}

if errevt := installEvents(ctx, c, cfg.Namespace, customizer, collection, force); errevt != nil {
if k8serrors.IsAlreadyExists(err) {
return err
if k8serrors.IsAlreadyExists(errevt) {
return errevt
}
fmt.Println("Warning: the operator will not be able to publish Kubernetes events. Try installing as cluster-admin to allow it to generate events.")
}

if errmtr := installServiceMonitors(ctx, c, cfg.Namespace, customizer, collection, force); errmtr != nil {
if k8serrors.IsAlreadyExists(errmtr) {
return errmtr
}
fmt.Println("Warning: the operator will not be able to create servicemonitors for metrics. Try installing as cluster-admin to allow the creation of servicemonitors.")
}

return nil
}

Expand Down Expand Up @@ -171,6 +178,13 @@ func installEvents(ctx context.Context, c client.Client, namespace string, custo
)
}

func installServiceMonitors(ctx context.Context, c client.Client, namespace string, customizer ResourceCustomizer, collection *kubernetes.Collection, force bool) error {
return ResourcesOrCollect(ctx, c, namespace, collection, force, customizer,
"operator-role-servicemonitors.yaml",
"operator-role-binding-servicemonitors.yaml",
)
}

// Platform installs the platform custom resource
// nolint: lll
func Platform(ctx context.Context, c client.Client, clusterType string, namespace string, registry v1.IntegrationPlatformRegistrySpec) (*v1.IntegrationPlatform, error) {
Expand Down

0 comments on commit 0b18732

Please sign in to comment.