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

[ISSUE-417] Fix CSI deployment via Operator on Openshift #39

Merged
merged 7 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions api/v1/components/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ type Scheduler struct {
Log *Log `json:"log,omitempty"`
Metrics *Metrics `json:"metrics,omitempty"`
Patcher *Patcher `json:"patcher,omitempty"`
ExtenderPort string `json:"extenderPort,omitempty"`
StorageProvisioner string `json:"storageProvisioner"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data:
apiVersion: v1
kind: Policy
extenders:
- urlPrefix: "http://127.0.0.1:8889"
- urlPrefix: "http://127.0.0.1:{{ .Values.scheduler.patcher.extender_port }}"
filterVerb: filter
prioritizeVerb: prioritize
weight: 1
Expand All @@ -38,7 +38,7 @@ data:
apiVersion: kubescheduler.config.k8s.io/v1beta1
kind: KubeSchedulerConfiguration
extenders:
- urlPrefix: "http://127.0.0.1:8889"
- urlPrefix: "http://127.0.0.1:{{ .Values.scheduler.patcher.extender_port }}"
filterVerb: filter
prioritizeVerb: prioritize
weight: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ spec:
metrics:
path: {{ .Values.scheduler.metrics.path }}
port: {{ .Values.scheduler.metrics.port }}
extenderPort: {{ .Values.scheduler.extender.port | quote }}
patcher:
enable: {{ .Values.scheduler.patcher.enable }}
image:
Expand Down
3 changes: 3 additions & 0 deletions charts/csi-baremetal-deployment/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ scheduler:
path: /metrics
port: 8787

extender:
port: 8889

# Patcher settings
patcher:
enable: false
Expand Down
3 changes: 2 additions & 1 deletion charts/csi-baremetal-operator/templates/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ spec:
name: manager
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
# Memory limit is increased due to bug in OpenShift 4.6 - https://bugzilla.redhat.com/show_bug.cgi?id=1904558
limits:
cpu: 100m
memory: 30Mi
memory: 100Mi
mishoyama marked this conversation as resolved.
Show resolved Hide resolved
requests:
cpu: 100m
memory: 20Mi
Expand Down
7 changes: 7 additions & 0 deletions charts/csi-baremetal-operator/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ rules:
- "*"
verbs:
- "*"
# Required for Openshift only
- apiGroups:
safronovD marked this conversation as resolved.
Show resolved Hide resolved
- config.openshift.io
resources:
- schedulers
verbs:
- "*"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *CSIDeployment) Update(ctx context.Context, csi *csibaremetalv1.Deployme
// Patching method for the scheduler depends on the platform
switch csi.Spec.Platform {
case platformOpenshift:
return c.patcher.PatchOpenShift(ctx, scheme)
return c.patcher.PatchOpenShift(ctx, csi)
default:
return c.patcher.Update(csi, scheme)

Expand Down
27 changes: 15 additions & 12 deletions pkg/scheduler_patcher_openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@ package pkg

import (
"context"
"fmt"

openshiftv1 "github.com/openshift/api/config/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

csibaremetalv1 "github.com/dell/csi-baremetal-operator/api/v1"
)

const (
openshiftNS = "openshift-config"
openshiftConfig = "scheduler-policy"

oshiftpolicyFile = "policy.cfg"
oshiftpolicy = `{
openshiftPolicyFile = "policy.cfg"
)

func (p *SchedulerPatcher) PatchOpenShift(ctx context.Context, csi *csibaremetalv1.Deployment) error {
openshiftPolicy := fmt.Sprintf(`{
"kind" : "Policy",
"apiVersion" : "v1",
"extenders": [
{
"urlPrefix": "http://127.0.0.1:$PORT",
"urlPrefix": "http://127.0.0.1:%s",
"filterVerb": "filter",
"enableHttps": false,
"nodeCacheCapable": false,
"ignorable": true
}
]
}`
)
}`, csi.Spec.Scheduler.ExtenderPort)

func (p *SchedulerPatcher) PatchOpenShift(ctx context.Context, scheme *runtime.Scheme) error {
cfClient := p.CoreV1().ConfigMaps(openshiftNS)
oscf, err := cfClient.Get(p.ctx, openshiftConfig, metav1.GetOptions{})
if err != nil {
Expand All @@ -40,8 +43,8 @@ func (p *SchedulerPatcher) PatchOpenShift(ctx context.Context, scheme *runtime.S
return err
}
} else {
if v, ok := oscf.Data[oshiftpolicyFile]; ok {
if v == oshiftpolicy {
if v, ok := oscf.Data[openshiftPolicyFile]; ok {
if v == openshiftPolicy {
p.Logger.Info("Configmap is already patched")
return nil
}
Expand All @@ -54,7 +57,7 @@ func (p *SchedulerPatcher) PatchOpenShift(ctx context.Context, scheme *runtime.S
}
}

_, err = cfClient.Create(p.ctx, createOpenshiftConfig(), metav1.CreateOptions{})
_, err = cfClient.Create(p.ctx, createOpenshiftConfig(openshiftPolicy), metav1.CreateOptions{})
if err != nil {
p.Logger.Error(err, "Failed to create configmap")
return err
Expand All @@ -79,14 +82,14 @@ func (p *SchedulerPatcher) UnPatchOpenShift(ctx context.Context) error {
return p.unpatchSheduler(ctx)
}

func createOpenshiftConfig() *corev1.ConfigMap {
func createOpenshiftConfig(policy string) *corev1.ConfigMap {
return &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: openshiftConfig,
Namespace: openshiftNS,
},
Data: map[string]string{oshiftpolicyFile: oshiftpolicy},
Data: map[string]string{openshiftPolicyFile: policy},
}
}

Expand Down