Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Rodriguez <[email protected]>
  • Loading branch information
javirln committed Aug 7, 2024
1 parent ff7d98e commit 7ecedad
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 55 deletions.
5 changes: 4 additions & 1 deletion .vib/chainloop/ginkgo/chainloop_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chainloop_test
import (
"flag"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -13,13 +14,15 @@ var (
releaseName string
namespace string
timeoutSeconds int
timeout time.Duration
)

func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
flag.StringVar(&releaseName, "name", "", "name of the primary statefulset")
flag.StringVar(&namespace, "namespace", "", "namespace where the application is running")
flag.IntVar(&timeoutSeconds, "timeout", 180, "timeout in seconds")
flag.IntVar(&timeoutSeconds, "timeout", 300, "timeout in seconds")
timeout = time.Duration(timeoutSeconds) * time.Second
}

func TestChainloop(t *testing.T) {
Expand Down
118 changes: 65 additions & 53 deletions .vib/chainloop/ginkgo/chainloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ package chainloop_test
import (
"context"
"fmt"
"time"

utils "github.com/bitnami/charts/.vib/common-tests/ginkgo-utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

const (
PollingInterval = 1 * time.Second
)

// portDefinition is a struct to define a port in a service
type portDefinition struct {
name string
Expand All @@ -29,7 +36,22 @@ var _ = Describe("Chainloop", Ordered, func() {
})

When("Chainloop chart is fully deployed", func() {
It("all services exposes expected ports", func() {
It("cas deployment is running", func() {
getReadyReplicas := func(ss *appsv1.Deployment) int32 { return ss.Status.ReadyReplicas }
getOpts := metav1.GetOptions{}

By("checking all the replicas are available")
stsName := fmt.Sprintf("%s-cas", releaseName)
dpl, err := c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
Expect(err).NotTo(HaveOccurred())
Expect(dpl.Status.Replicas).NotTo(BeZero())
origReplicas := *dpl.Spec.Replicas

Eventually(func() (*appsv1.Deployment, error) {
return c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getReadyReplicas, Equal(origReplicas)))

By("checking all the services are available")
svcs := []struct {
name string
ports []portDefinition
Expand All @@ -52,6 +74,46 @@ var _ = Describe("Chainloop", Ordered, func() {
},
},
},
}

for _, inSvc := range svcs {
svcName := fmt.Sprintf("%v-%v", releaseName, inSvc.name)
svc, err := c.CoreV1().Services(namespace).Get(ctx, svcName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

for _, port := range inSvc.ports {
outPort, err := utils.SvcGetPortByName(svc, port.name)
Expect(err).NotTo(HaveOccurred())
Expect(outPort).NotTo(BeNil())
Expect(outPort).To(Equal(port.number))
}
}

By("checking main container image is running")
_, err = utils.DplGetContainerImage(dpl, "cas")
Expect(err).NotTo(HaveOccurred())
})

It("controlplane deployment is running", func() {
getReadyReplicas := func(ss *appsv1.Deployment) int32 { return ss.Status.ReadyReplicas }
getOpts := metav1.GetOptions{}

By("checking all the replicas are available")
stsName := fmt.Sprintf("%s-controlplane", releaseName)
dpl, err := c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
Expect(err).NotTo(HaveOccurred())
Expect(dpl.Status.Replicas).NotTo(BeZero())
origReplicas := *dpl.Spec.Replicas

Eventually(func() (*appsv1.Deployment, error) {
return c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getReadyReplicas, Equal(origReplicas)))

By("checking all the services are available")
svcs := []struct {
name string
ports []portDefinition
}{
{
name: "controlplane",
ports: []portDefinition{
Expand All @@ -70,39 +132,6 @@ var _ = Describe("Chainloop", Ordered, func() {
},
},
},
{
name: "postgresql",
ports: []portDefinition{
{
name: "tcp-postgresql",
number: "5432",
},
},
},
{
name: "vault-server",
ports: []portDefinition{
{
name: "http",
number: "8200",
}, {
name: "https-internal",
number: "8201",
},
},
},
{
name: "dex",
ports: []portDefinition{
{
name: "http",
number: "5556",
}, {
name: "grpc",
number: "5557",
},
},
},
}

for _, inSvc := range svcs {
Expand All @@ -117,27 +146,10 @@ var _ = Describe("Chainloop", Ordered, func() {
Expect(outPort).To(Equal(port.number))
}
}
})

It("all pods are running", func() {
pods, err := c.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
By("checking main container image is running")
_, err = utils.DplGetContainerImage(dpl, "controlplane")
Expect(err).NotTo(HaveOccurred())

for _, pod := range pods.Items {
_, err := utils.IsPodRunning(ctx, c.CoreV1(), namespace, pod.Name)
Expect(err).NotTo(HaveOccurred())
}
})

It("all deployments are running", func() {
dpls := []string{"cas", "controlplane", "dex", "vault-injector"}

for _, dplName := range dpls {
dpl, err := c.AppsV1().Deployments(namespace).Get(ctx, fmt.Sprintf("%v-%v", releaseName, dplName), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

Expect(dpl.Status.ReadyReplicas).To(Equal(*dpl.Spec.Replicas))
}
})
})

Expand Down
2 changes: 1 addition & 1 deletion bitnami/chainloop/templates/cas/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
{{- include "common.tplvalues.render" (dict "value" .Values.cas.initContainers "context" $) | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
- name: cas
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.cas.containerSecurityContext "context" $) | nindent 12 }}
image: {{ include "chainloop.cas.image" . }}
imagePullPolicy: {{ .Values.cas.image.pullPolicy }}
Expand Down

0 comments on commit 7ecedad

Please sign in to comment.