Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
- name: Run golangci-lint
uses: reviewdog/action-golangci-lint@f9bba13753278f6a73b27a56a3ffb1bfda90ed71 # v2
with:
go_version: "1.26.5"
fail_level: "none"

build:
Expand All @@ -31,7 +30,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@be3c94b385c4f180051c996d336f57a34c397495 # v3
with:
go-version: '1.26.5'
go-version-file: 'go.mod'

- name: Install dependencies
run: go get ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@be3c94b385c4f180051c996d336f57a34c397495 # v3
with:
go-version: '1.26.5'
go-version-file: 'go.mod'

- uses: anchore/sbom-action/download-syft@f8bdd1d8ac5e901a77a92f111440fdb1b593736b # v0.20.6

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# golang:1.26-alpine
FROM golang@sha256:0178a641fbb4858c5f1b48e34bdaabe0350a330a1b1149aabd498d0699ff5fb2 AS builder
# golang:1.26.6-alpine3.24
FROM golang@sha256:3889b425f035be855a72fb4755265311293b6d414521f0a519d819df32222d83 AS builder

ARG VERSION
ARG SCANNER_IMG_VERSION
Expand Down
17 changes: 8 additions & 9 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ func createTestDestroy(t *testing.T, gc helpers.GenericCluster) {
defer gc.Destroy(t) // safe to call also when the cluster has not been created
gc.Create(t)

ctx := context.Background()
kubeConfig := gc.KubeConfigGet()
svc, err := kubeops.NewServiceFromKubeConfigFile(kubeConfig, hclog.NewNullLogger())
if err != nil {
t.Logf("Failed to build kubernetes client: %s", err)
t.Fatal(err)
}

if err := svc.PingHealthEndpoint(ctx, "/healthz"); err != nil {
if err := svc.PingHealthEndpoint(t.Context(), "/healthz"); err != nil {
t.Logf("Failed to ping kubernetes server: %s", err)
t.Fatal(err)
}
Expand All @@ -195,10 +194,10 @@ func createTestDestroy(t *testing.T, gc helpers.GenericCluster) {
options := k8s.NewKubectlOptions("", kubeConfig, "")

// let's wait for all the nodes to be ready
k8s.WaitUntilAllNodesReady(t, options, 20, 1*time.Minute)
k8s.WaitUntilAllNodesReadyContext(t, t.Context(), options, 20, 1*time.Minute)

// we apply all the manifests and then run
k8s.KubectlApply(t, options, "./manifests/workload.yaml")
k8s.KubectlApplyContext(t, t.Context(), options, "./manifests/workload.yaml")
namespaces := waitUntilManifestReady(t, svc, "./manifests/workload.yaml")

netAssertTestCases, err := data.ReadTestsFromFile(testCasesFile)
Expand All @@ -207,10 +206,10 @@ func createTestDestroy(t *testing.T, gc helpers.GenericCluster) {
}

// create the network policies
k8s.KubectlApply(t, options, "./manifests/networkpolicies.yaml")
k8s.KubectlApplyContext(t, t.Context(), options, "./manifests/networkpolicies.yaml")

// run the sample tests
runTests(ctx, t, svc, netAssertTestCases)
runTests(t.Context(), t, svc, netAssertTestCases)

if gc.SkipNetPolTests() {
return
Expand All @@ -230,14 +229,14 @@ func createTestDestroy(t *testing.T, gc helpers.GenericCluster) {
for _, ns := range namespaces {
nsKubeOptions := k8s.NewKubectlOptions("", kubeConfig, ns)

k8s.KubectlApplyFromString(t, nsKubeOptions, denyAllPolicyBody)
k8s.KubectlApplyFromStringContext(t, t.Context(), nsKubeOptions, denyAllPolicyBody)

k8s.WaitUntilNetworkPolicyAvailable(t, nsKubeOptions, "default-deny-all", 10, 5*time.Second)
k8s.WaitUntilNetworkPolicyAvailableContext(t, t.Context(), nsKubeOptions, "default-deny-all", 10, 5*time.Second)
require.NoError(t, err, "Error, the NetworkPolicy should exist in namespace %s", ns)
}

// run the tests with network policies blocking everything
runTests(ctx, t, svc, netAssertTestCases)
runTests(t.Context(), t, svc, netAssertTestCases)
}

func runTests(ctx context.Context, t *testing.T, svc *kubeops.Service, netAssertTestCases data.Tests) {
Expand Down
14 changes: 6 additions & 8 deletions e2e/helpers/eks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package helpers

import (
"context"
"os"
"testing"
"time"
Expand Down Expand Up @@ -65,10 +64,10 @@ func NewEKSCluster(t *testing.T, terraformDir, clusterNameSuffix string, nm Netw

func (g *EKSCluster) Create(t *testing.T) {
// terraform init
terraform.InitAndPlan(t, g.opts)
terraform.InitAndPlanContext(t, t.Context(), g.opts)

// terraform apply
terraform.Apply(t, g.opts)
terraform.ApplyContext(t, t.Context(), g.opts)

if g.networkMode == Calico {
g.installCalico(t)
Expand All @@ -78,7 +77,6 @@ func (g *EKSCluster) Create(t *testing.T) {
func (g *EKSCluster) installCalico(t *testing.T) {
// once the cluster is ready, we need to follow the instructions here
// https://docs.tigera.io/calico/3.26/getting-started/kubernetes/managed-public-cloud/eks
ctx := context.Background()

lg := logger.NewHCLogger("INFO", "netassertv2-e2e-calico", os.Stdout)

Expand All @@ -89,7 +87,7 @@ func (g *EKSCluster) installCalico(t *testing.T) {

// kubectl delete daemonset -n kube-system aws-node
err = svc.Client.AppsV1().DaemonSets("kube-system").Delete(
ctx, "aws-node", metav1.DeleteOptions{})
t.Context(), "aws-node", metav1.DeleteOptions{})

if err != nil {
if !apierrors.IsNotFound(err) {
Expand All @@ -102,7 +100,7 @@ func (g *EKSCluster) installCalico(t *testing.T) {
options := k8s.NewKubectlOptions("", g.kubeConfigPath, "")

// we now apply calico CNI manifest
k8s.KubectlApply(t, options, g.terraformDir+"/../calico-3.26.4.yaml")
k8s.KubectlApplyContext(t, t.Context(), options, g.terraformDir+"/../calico-3.26.4.yaml")

// update the desired_size variable to 3
g.opts.Vars["desired_size"] = 3
Expand All @@ -111,7 +109,7 @@ func (g *EKSCluster) installCalico(t *testing.T) {
newTFOptions := terraform.WithDefaultRetryableErrors(t, g.opts)
// terraform apply the new options
// this terraform apply should scale up the worker nodes with Calico CNI
if _, err := terraform.InitAndApplyE(t, newTFOptions); err != nil {
if _, err := terraform.InitAndApplyContextE(t, t.Context(), newTFOptions); err != nil {
t.Fatalf("failed to run terraform init and apply: %s", err)
}

Expand All @@ -121,7 +119,7 @@ func (g *EKSCluster) installCalico(t *testing.T) {

func (g *EKSCluster) Destroy(t *testing.T) {
if g.opts != nil {
terraform.Destroy(t, g.opts)
terraform.DestroyContext(t, t.Context(), g.opts)
}
}

Expand Down
6 changes: 3 additions & 3 deletions e2e/helpers/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func NewGKECluster(t *testing.T, terraformDir, clusterNameSuffix string, nm Netw

func (g *GKECluster) Create(t *testing.T) {
// terraform init
terraform.InitAndPlan(t, g.opts)
terraform.InitAndPlanContext(t, t.Context(), g.opts)

// terraform apply
terraform.Apply(t, g.opts)
terraform.ApplyContext(t, t.Context(), g.opts)
}

func (g *GKECluster) Destroy(t *testing.T) {
if g.opts != nil {
terraform.Destroy(t, g.opts)
terraform.DestroyContext(t, t.Context(), g.opts)
}
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/helpers/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (k *KindCluster) Create(t *testing.T) {
k.provider = provider

options := k8s.NewKubectlOptions("", k.kubeConfigPath, "")
k8s.KubectlApply(t, options, "https://raw.githubusercontent.com/projectcalico/calico/v3.31.3/manifests/calico.yaml")
k8s.KubectlApplyContext(t, t.Context(), options, "https://raw.githubusercontent.com/projectcalico/calico/v3.31.3/manifests/calico.yaml")
}

func (k *KindCluster) Destroy(t *testing.T) {
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/controlplaneio/netassert/v2

go 1.26.5
go 1.26.6

require (
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -31,11 +31,9 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.32.28 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.19.27 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.30 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.22.31 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.2.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.31 // indirect
github.com/aws/aws-sdk-go-v2/service/acm v1.42.0 // indirect
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.69.0 // indirect
Expand Down Expand Up @@ -81,7 +79,6 @@ require (
github.com/go-openapi/swag/cmdutils v0.27.0 // indirect
github.com/go-openapi/swag/conv v0.27.0 // indirect
github.com/go-openapi/swag/fileutils v0.27.0 // indirect
github.com/go-openapi/swag/jsonname v0.27.0 // indirect
github.com/go-openapi/swag/jsonutils v0.27.0 // indirect
github.com/go-openapi/swag/loading v0.27.0 // indirect
github.com/go-openapi/swag/mangling v0.27.0 // indirect
Expand Down Expand Up @@ -119,7 +116,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
Loading
Loading