Skip to content

Commit

Permalink
Activation of the new webhook logic
Browse files Browse the repository at this point in the history
This commit activates the new webhook logic, the right node affinities and added to the pod.
  • Loading branch information
Andreagit97 committed Jul 8, 2021
1 parent 189d5da commit 0e3d7c2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion deployments/liqo/README.md
Expand Up @@ -68,7 +68,7 @@
| webhook.imageName | string | `"liqo/liqo-webhook"` | webhook image repository |
| webhook.initContainer.imageName | string | `"liqo/webhook-configuration"` | webhook init container image repository |
| webhook.mutatingWebhookConfiguration.annotations | object | `{}` | mutatingWebhookConfiguration annotations |
| webhook.mutatingWebhookConfiguration.namespaceSelector | object | `{"liqo.io/enabled":"true"}` | The label that needs to be applied to a namespace to make it eligible for pod offloading in a remote cluster |
| webhook.mutatingWebhookConfiguration.namespaceSelector | object | `{"liqo.io/scheduling":"true"}` | The label that needs to be applied to a namespace to make it eligible for pod offloading in a remote cluster |
| webhook.pod.annotations | object | `{}` | webhook pod annotations |
| webhook.pod.labels | object | `{}` | webhook pod labels |
| webhook.service.annotations | object | `{}` | webhook service annotations |
2 changes: 1 addition & 1 deletion deployments/liqo/templates/liqo-webhook.yaml
Expand Up @@ -41,4 +41,4 @@ webhooks:
failurePolicy: Ignore
namespaceSelector:
matchLabels:
{{- toYaml .Values.webhook.mutatingWebhookConfiguration.namespaceSelector | nindent 8 }}
liqo.io/scheduling-enabled: "true"
2 changes: 1 addition & 1 deletion deployments/liqo/values.yaml
Expand Up @@ -169,7 +169,7 @@ webhook:
annotations: {}
# -- The label that needs to be applied to a namespace to make it eligible for pod offloading in a remote cluster
namespaceSelector:
liqo.io/enabled: "true"
liqo.io/scheduling: "true"

peeringRequest:
pod:
Expand Down
21 changes: 16 additions & 5 deletions pkg/mutate/mutate.go
Expand Up @@ -8,8 +8,10 @@ import (
admissionv1beta1 "k8s.io/api/admission/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"

offv1alpha1 "github.com/liqotech/liqo/apis/offloading/v1alpha1"
liqoconst "github.com/liqotech/liqo/pkg/consts"
)

Expand Down Expand Up @@ -61,11 +63,20 @@ func (s *MutationServer) Mutate(body []byte) ([]byte, error) {
return nil, err
}

pod.Spec.Tolerations = append(pod.Spec.Tolerations, corev1.Toleration{
Key: liqoconst.VirtualNodeTolerationKey,
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoExecute,
})
// Get the NamespaceOffloading associated with the pod Namespace. If there is no NamespaceOffloading for that
// Namespace, it is an error the liqo.io/scheduling label shouldn't be on this namespace.
namespaceOffloading := &offv1alpha1.NamespaceOffloading{}
if err = s.webhookClient.Get(s.ctx, types.NamespacedName{
Namespace: pod.Namespace,
Name: liqoconst.DefaultNamespaceOffloadingName,
}, namespaceOffloading); err != nil {
return nil, fmt.Errorf("%w -> unable to get the NamespaceOffloading for the Namespace: %s", err, pod.Namespace)
}

klog.V(5).Infof("The namespace '%s' has a NamespaceOffloading resource", pod.Namespace)
if err = mutatePod(namespaceOffloading, pod); err != nil {
return nil, err
}

target, err := json.Marshal(pod)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/mutate/server.go
Expand Up @@ -27,12 +27,14 @@ type MutationServer struct {

webhookClient client.Client
config *MutationConfig
ctx context.Context
}

// NewMutationServer creates a new mutation server.
func NewMutationServer(ctx context.Context, c *MutationConfig) (*MutationServer, error) {
s := &MutationServer{}
s.config = c
s.ctx = ctx

// This scheme is necessary for the WebhookClient.
scheme := runtime.NewScheme()
Expand Down
19 changes: 10 additions & 9 deletions test/e2e/peering_e2e/basic_test.go
Expand Up @@ -90,16 +90,17 @@ var _ = Describe("Liqo E2E", func() {
})

Context("E2E Testing with Online Boutique", func() {
It("Testing online boutique", func() {
options := k8s.NewKubectlOptions("", testContext.Clusters[0].KubeconfigPath, microservices.TestNamespaceName)
defer GinkgoRecover()
err := microservices.DeployApp(GinkgoT(), testContext.Clusters[0].KubeconfigPath)
Expect(err).ShouldNot(HaveOccurred())
microservices.WaitDemoApp(GinkgoT(), options)

options := k8s.NewKubectlOptions("", testContext.Clusters[0].KubeconfigPath, microservices.TestNamespaceName)
defer GinkgoRecover()
err := microservices.DeployApp(GinkgoT(), testContext.Clusters[0].KubeconfigPath)
Expect(err).ShouldNot(HaveOccurred())
microservices.WaitDemoApp(GinkgoT(), options)

By("Verify Online Boutique Connectivity")
err = microservices.CheckApplicationIsWorking(GinkgoT(), options)
Expect(err).ShouldNot(HaveOccurred())
By("Verify Online Boutique Connectivity")
err = microservices.CheckApplicationIsWorking(GinkgoT(), options)
Expect(err).ShouldNot(HaveOccurred())
})
})

AfterSuite(func() {
Expand Down

0 comments on commit 0e3d7c2

Please sign in to comment.