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

Bug 1838297: Creating role and roleBinding when enabling monitoring for an operator #5529

Merged
merged 1 commit into from May 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,7 +35,7 @@ import {
PackageManifestModel,
ClusterServiceVersionModel,
} from '../../models';
import { NamespaceModel } from '@console/internal/models';
import { NamespaceModel, RoleBindingModel, RoleModel } from '@console/internal/models';
import {
OperatorGroupKind,
PackageManifestKind,
Expand Down Expand Up @@ -216,6 +216,44 @@ export const OperatorHubSubscribeForm: React.FC<OperatorHubSubscribeFormProps> =
},
};

const rbacName = `${selectedTargetNamespace}-prometheus`;
const prometheusRole = {
kind: RoleModel.kind,
apiVersion: `${RoleModel.apiGroup}/${RoleModel.apiVersion}`,
metadata: {
name: rbacName,
namespace: selectedTargetNamespace,
},
rules: [
{
apiGroups: [''],
resources: ['services', 'endpoints', 'pods'],
verbs: ['get', 'list', 'watch'],
},
],
};

const prometheusRoleBinding = {
kind: RoleBindingModel.kind,
apiVersion: `${RoleBindingModel.apiGroup}/${RoleBindingModel.apiVersion}`,
metadata: {
name: rbacName,
namespace: selectedTargetNamespace,
},
roleRef: {
kind: 'Role',
name: rbacName,
apiGroup: RoleBindingModel.apiGroup,
},
subjects: [
{
kind: 'ServiceAccount',
name: 'prometheus-operator',
namespace: 'openshift-monitoring',
},
],
};

const operatorGroup: OperatorGroupKind = {
apiVersion: apiVersionForModel(OperatorGroupModel) as OperatorGroupKind['apiVersion'],
kind: 'OperatorGroup',
Expand Down Expand Up @@ -252,6 +290,10 @@ export const OperatorHubSubscribeForm: React.FC<OperatorHubSubscribeFormProps> =
try {
if (isSuggestedNamespaceSelected && !suggestedNamespaceExists) {
await k8sCreate(NamespaceModel, ns);
if (operatorRequestsMonitoring && enableMonitoring) {
await k8sCreate(RoleModel, prometheusRole);
await k8sCreate(RoleBindingModel, prometheusRoleBinding);
}
}
if (
!props.operatorGroup.data.some(
Expand Down