Skip to content

Commit

Permalink
test: πŸ’ update namespaces to use psa labels (#2495)
Browse files Browse the repository at this point in the history
* test: πŸ’ update namespaces to use psa labels
  • Loading branch information
jaskaransarkaria authored Oct 11, 2023
1 parent 91aa764 commit db3bea3
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
13 changes: 12 additions & 1 deletion test/certmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ministryofjustice/cloud-platform-infrastructure/test/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DefaultCert is the struct of the default certificate used
Expand Down Expand Up @@ -74,7 +75,17 @@ var _ = Describe("cert-manager", FlakeAttempts(2), func() {
namespace = fmt.Sprintf("%s-certman-%s", c.Prefix, strings.ToLower(random.UniqueId()))
options = k8s.NewKubectlOptions("", "", namespace)
host = fmt.Sprintf("%s.%s", namespace, testDomain)
k8s.CreateNamespace(GinkgoT(), options, namespace)

nsObject := metav1.ObjectMeta{
Name: namespace,
Labels: map[string]string{
"pod-security.kubernetes.io/audit": "restricted",
},
}

err := k8s.CreateNamespaceWithMetadataE(GinkgoT(), options, nsObject)
Expect(err).NotTo(HaveOccurred())

app := helpers.HelloworldOpt{
Hostname: host,
Class: "default",
Expand Down
10 changes: 9 additions & 1 deletion test/external_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// External DNS tests the external-dns function in a cluster can create
Expand All @@ -33,7 +34,14 @@ var _ = Describe("external-dns", func() {
options = k8s.NewKubectlOptions("", "", namespaceName)
domain = fmt.Sprintf("%s.%s", namespaceName, testDomain)

err := k8s.CreateNamespaceE(GinkgoT(), options, namespaceName)
nsObject := metav1.ObjectMeta{
Name: namespaceName,
Labels: map[string]string{
"pod-security.kubernetes.io/audit": "restricted",
},
}

err := k8s.CreateNamespaceWithMetadataE(GinkgoT(), options, nsObject)
Expect(err).ToNot(HaveOccurred())

tpl, err := helpers.TemplateFile("./fixtures/external-dns-ingress.yaml.tmpl", "external-dns-ingress.yaml.tmpl", template.FuncMap{
Expand Down
10 changes: 9 additions & 1 deletion test/ingress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/onsi/gomega"

"github.com/ministryofjustice/cloud-platform-infrastructure/test/helpers"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = Describe("ingress-controllers", func() {
Expand All @@ -26,7 +27,14 @@ var _ = Describe("ingress-controllers", func() {
options = k8s.NewKubectlOptions("", "", namespaceName)
url = fmt.Sprintf("https://%s", host)

err := k8s.CreateNamespaceE(GinkgoT(), options, namespaceName)
nsObject := metav1.ObjectMeta{
Name: namespaceName,
Labels: map[string]string{
"pod-security.kubernetes.io/audit": "restricted",
},
}

err := k8s.CreateNamespaceWithMetadataE(GinkgoT(), options, nsObject)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
10 changes: 9 additions & 1 deletion test/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ var _ = Describe("logging", func() {
namespace = fmt.Sprintf("%s-logs-%s", c.Prefix, strings.ToLower(random.UniqueId()))
options = k8s.NewKubectlOptions("", "", namespace)
host := fmt.Sprintf("%s.%s", namespace, testDomain)
err := k8s.CreateNamespaceE(GinkgoT(), options, namespace)

nsObject := metav1.ObjectMeta{
Name: namespace,
Labels: map[string]string{
"pod-security.kubernetes.io/audit": "restricted",
},
}

err := k8s.CreateNamespaceWithMetadataE(GinkgoT(), options, nsObject)
Expect(err).ToNot(HaveOccurred())
class := "default"

Expand Down
10 changes: 9 additions & 1 deletion test/modsec_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/random"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/ministryofjustice/cloud-platform-infrastructure/test/helpers"
)
Expand All @@ -32,7 +33,14 @@ var _ = Describe("modsec-ingress-controller", func() {
goodUrl = fmt.Sprintf("https://%s", host)
badUrl = fmt.Sprintf("%s?exec=/bin/bash", url)

err := k8s.CreateNamespaceE(GinkgoT(), options, namespaceName)
nsObject := metav1.ObjectMeta{
Name: namespaceName,
Labels: map[string]string{
"pod-security.kubernetes.io/audit": "restricted",
},
}

err := k8s.CreateNamespaceWithMetadataE(GinkgoT(), options, nsObject)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
11 changes: 10 additions & 1 deletion test/modsec_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ministryofjustice/cloud-platform-infrastructure/test/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type PhraseData struct {
Expand Down Expand Up @@ -122,7 +123,15 @@ var _ = Describe("logging", Ordered, func() {
namespace = fmt.Sprintf("%s-logs-%s", c.Prefix, uniqueId)
options = k8s.NewKubectlOptions("", "", namespace)
host := fmt.Sprintf("%s.%s", namespace, testDomain)
err := k8s.CreateNamespaceE(GinkgoT(), options, namespace)

nsObject := metav1.ObjectMeta{
Name: namespace,
Labels: map[string]string{
"pod-security.kubernetes.io/audit": "restricted",
},
}

err := k8s.CreateNamespaceWithMetadataE(GinkgoT(), options, nsObject)
Expect(err).ToNot(HaveOccurred())
class := "modsec"

Expand Down

0 comments on commit db3bea3

Please sign in to comment.