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

Mount OVS socket unconditionally #861

Merged
merged 1 commit into from Nov 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions build/Dockerfile.operator.openshift
Expand Up @@ -13,8 +13,6 @@ COPY deploy/handler/service_account.yaml /bindata/kubernetes-nmstate/rbac/
COPY deploy/handler/role.yaml /bindata/kubernetes-nmstate/rbac/
COPY deploy/handler/role_binding.yaml /bindata/kubernetes-nmstate/rbac/

ENV ENABLE_OVS=""

ENTRYPOINT ["manager"]

LABEL io.k8s.display-name="kubernetes-nmstate-operator" \
Expand Down
2 changes: 0 additions & 2 deletions controllers/operator/nmstate_controller.go
Expand Up @@ -213,8 +213,6 @@ func (r *NMStateReconciler) applyHandler(instance *nmstatev1.NMState) error {
data.Data["HandlerNodeSelector"] = archAndCRNodeSelector
data.Data["HandlerTolerations"] = handlerTolerations
data.Data["HandlerAffinity"] = corev1.Affinity{}
_, enableOVS := os.LookupEnv("ENABLE_OVS")
data.Data["EnableOVS"] = enableOVS
// TODO: This is just a place holder to make template renderer happy
// proper variable has to be read from env or CR
data.Data["CARotateInterval"] = ""
Expand Down
84 changes: 0 additions & 84 deletions controllers/operator/nmstate_controller_test.go
Expand Up @@ -305,65 +305,6 @@ var _ = Describe("NMState controller reconcile", func() {
Expect(anyTolerationsPresent(infraTolerations, ds.Spec.Template.Spec.Tolerations)).To(BeFalse())
})
})
Context("when OVS is NOT enabled", func() {
var (
request ctrl.Request
)
BeforeEach(func() {
s := scheme.Scheme
s.AddKnownTypes(nmstatev1.GroupVersion,
&nmstatev1.NMState{},
)
objs := []runtime.Object{&nmstate}
// Create a fake client to mock API calls.
cl = fake.NewFakeClientWithScheme(s, objs...)
reconciler.Client = cl
request.Name = existingNMStateName
result, err := reconciler.Reconcile(context.Background(), request)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal(ctrl.Result{}))
})
It("should not mount host OVS socket at handler", func() {
handlerDs := &appsv1.DaemonSet{}
handlerKey := types.NamespacedName{Namespace: handlerNamespace, Name: handlerPrefix + "-nmstate-handler"}
err := cl.Get(context.TODO(), handlerKey, handlerDs)
Expect(err).ToNot(HaveOccurred())
Expect(hasOVSSocketMounted(*handlerDs)).To(BeFalse())
})
})
Context("when OVS is enabled", func() {
var (
request ctrl.Request
)
BeforeEach(func() {
os.Setenv("ENABLE_OVS", "")
})
BeforeEach(func() {
s := scheme.Scheme
s.AddKnownTypes(nmstatev1.GroupVersion,
&nmstatev1.NMState{},
)
objs := []runtime.Object{&nmstate}
// Create a fake client to mock API calls.
cl = fake.NewFakeClientWithScheme(s, objs...)
reconciler.Client = cl
request.Name = existingNMStateName
result, err := reconciler.Reconcile(context.Background(), request)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal(ctrl.Result{}))
})
AfterEach(func() {
os.Unsetenv("ENABLE_OVS")
})

It("should not mount host OVS socket at handler", func() {
handlerDs := &appsv1.DaemonSet{}
handlerKey := types.NamespacedName{Namespace: handlerNamespace, Name: handlerPrefix + "-nmstate-handler"}
err := cl.Get(context.TODO(), handlerKey, handlerDs)
Expect(err).ToNot(HaveOccurred())
Expect(hasOVSSocketMounted(*handlerDs)).To(BeTrue())
})
})
})

func copyManifest(src, dst string) error {
Expand Down Expand Up @@ -472,31 +413,6 @@ func isSuperset(ss, t corev1.Toleration) bool {
}
}

func hasOVSSocketHostPath(ds appsv1.DaemonSet) bool {
for _, v := range ds.Spec.Template.Spec.Volumes {
if v.Name == "ovs-socket" &&
v.HostPath != nil &&
v.HostPath.Path == "/run/openvswitch/db.sock" &&
v.HostPath.Type != nil &&
*v.HostPath.Type == corev1.HostPathSocket {
return true
}
}
return false
}

func hasOVSSocketMounted(ds appsv1.DaemonSet) bool {
if !hasOVSSocketHostPath(ds) {
return false
}
for _, v := range ds.Spec.Template.Spec.Containers[0].VolumeMounts {
if v.Name == "ovs-socket" && v.MountPath == "/run/openvswitch/db.sock" {
return true
}
}
return false
}

//allTolerationsPresent check if all tolerations from toBeCheckedTolerations are superseded by actualTolerations.
func allTolerationsPresent(toBeCheckedTolerations []corev1.Toleration, actualTolerations []corev1.Toleration) bool {
tolerationsFound := true
Expand Down
5 changes: 0 additions & 5 deletions deploy/handler/operator.yaml
Expand Up @@ -256,10 +256,8 @@ spec:
mountPath: /run/dbus/system_bus_socket
- name: nmstate-lock
mountPath: /var/k8s_nmstate
{{if .EnableOVS}}
- name: ovs-socket
mountPath: /run/openvswitch/db.sock
{{end}}
securityContext:
privileged: true
readinessProbe:
Expand All @@ -278,12 +276,9 @@ spec:
- name: nmstate-lock
hostPath:
path: /var/k8s_nmstate
{{if .EnableOVS}}
- name: ovs-socket
hostPath:
path: /run/openvswitch/db.sock
type: Socket
{{end}}
---
apiVersion: v1
kind: Service
Expand Down