Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
test/calic: initial commit
Browse files Browse the repository at this point in the history
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 <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Mar 23, 2020
1 parent cbfa8ad commit 8f0c575
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions test/calico/calico_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 8f0c575

Please sign in to comment.