From 8f0c575787ce0ba542461bd24efaa7f8fe92972f Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 23 Mar 2020 14:45:31 +0100 Subject: [PATCH] test/calic: initial commit This commit adds initial test for Calico, which checks, that each Node object in the cluster has associated HostEndpoint Calico object, which ensures, that GlobalNetworkPolicy objects take effect. Refs #137. Signed-off-by: Mateusz Gozdek --- test/calico/calico_test.go | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/calico/calico_test.go diff --git a/test/calico/calico_test.go b/test/calico/calico_test.go new file mode 100644 index 000000000..769e46344 --- /dev/null +++ b/test/calico/calico_test.go @@ -0,0 +1,67 @@ +// Copyright 2020 The Lokomotive Authors +// +// Licensed 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. + +// +build packet +// +build poste2e + +package calico + +import ( + "context" + "testing" + + "github.com/projectcalico/libcalico-go/lib/apiconfig" + client "github.com/projectcalico/libcalico-go/lib/clientv3" + "github.com/projectcalico/libcalico-go/lib/options" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/kinvolk/lokomotive/test/components/util" +) + +func TestHostEndpoints(t *testing.T) { + // Build Calico client. + cac := apiconfig.NewCalicoAPIConfig() + cac.Spec.DatastoreType = apiconfig.Kubernetes + cac.Spec.Kubeconfig = util.KubeconfigPath(t) + + c, err := client.New(*cac) + if err != nil { + t.Fatalf("failed creating Calico client: %v", err) + } + + // Build list of nodes which has associated HostEndpoint object. + hostEndpointList, err := c.HostEndpoints().List(context.TODO(), options.ListOptions{}) + if err != nil { + t.Fatalf("failed getting hostendpoint objects: %v", err) + } + + endpoints := map[string]struct{}{} + + for _, v := range hostEndpointList.Items { + endpoints[v.Spec.Node] = struct{}{} + } + + cs := util.CreateKubeClient(t) + + nodes, err := cs.CoreV1().Nodes().List(metav1.ListOptions{}) + if err != nil { + t.Fatalf("failed getting list of nodes in the cluster: %v", err) + } + + for _, v := range nodes.Items { + if _, ok := endpoints[v.Name]; !ok { + t.Errorf("no HostEndpoint object found for node %q", v.Name) + } + } +}