Skip to content

Commit

Permalink
Enable k8s tests (#1498)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl authored Dec 17, 2024
1 parent 562a870 commit 3dded98
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 24 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/k8s-e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: (k8s package) E2E tests
# disabling for now, as they always fail
#on:
# pull_request:
on:
pull_request:

concurrency:
group: e2e-tests-k8s-${{ github.ref }}
Expand Down Expand Up @@ -74,7 +73,7 @@ jobs:
- name: Load Nix
run: nix develop -c sh -c "cd lib &&go mod download"
- name: Setup environment
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@d2f9642bcc24a73400568756f24b72c188ac7a9a # v2.3.31
uses: smartcontractkit/.github/actions/ctf-setup-run-tests-environment@49cb1613e96c9ce17f7290e4dabd38f43aa9bd4d # [email protected]
with:
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
Expand All @@ -84,7 +83,7 @@ jobs:
- name: Run Tests
env:
LOCAL_CHARTS: true
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@d2f9642bcc24a73400568756f24b72c188ac7a9a # v2.3.31
uses: smartcontractkit/.github/actions/ctf-run-tests@b8731364b119e88983e94b0c4da87fc27ddb41b8 # [email protected]
with:
cl_repo: ${{ env.CHAINLINK_IMAGE }}
cl_image_tag: ${{ env.CHAINLINK_VERSION }}
Expand All @@ -97,7 +96,6 @@ jobs:
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
run_setup: false
- name: Upload test log
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
4 changes: 2 additions & 2 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ k8s_test_e2e:
go test ./k8s/e2e/local-runner -count 1 -test.parallel=12 -v $(args)

k8s_test_e2e_ci: go_mod
go test ./k8s/e2e/local-runner -count 1 -test.parallel=14 -test.timeout=1h -json 2>&1 | tee /tmp/gotest.log | gotestloghelper -ci -singlepackage
CHAINLINK_USER_TEAM=TT go test ./k8s/e2e/local-runner -count 1 -test.parallel=14 -test.timeout=1h -json 2>&1 | tee /tmp/gotest.log | gotestloghelper -ci -singlepackage

k8s_test_e2e_ci_remote_runner: go_mod
go test ./k8s/e2e/remote-runner -count 1 -test.parallel=20 -test.timeout=1h -json 2>&1 | tee /tmp/remoterunnergotest.log | gotestloghelper -ci -singlepackage
CHAINLINK_USER_TEAM=TT go test ./k8s/e2e/remote-runner -count 1 -test.parallel=20 -test.timeout=1h -json 2>&1 | tee /tmp/remoterunnergotest.log | gotestloghelper -ci -singlepackage

.PHONY: examples
examples:
Expand Down
18 changes: 15 additions & 3 deletions lib/k8s/e2e/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ var (
)

func GetTestEnvConfig(t *testing.T) *environment.Config {
testType := "functional"
product := "internal-k8s-test-runner"

nsLabels, err := environment.GetRequiredChainLinkNamespaceLabels(product, testType)
require.NoError(t, err, "Error creating required chain.link labels for namespace")

workloadPodLabels, err := environment.GetRequiredChainLinkWorkloadAndPodLabels(product, testType)
require.NoError(t, err, "Error creating required chain.link labels for workloads and pods")

return &environment.Config{
NamespacePrefix: TestEnvType,
Labels: []string{testSelector},
Test: t,
NamespacePrefix: TestEnvType,
Test: t,
Labels: nsLabels,
WorkloadLabels: workloadPodLabels,
PodLabels: workloadPodLabels,
SkipRequiredChainLinkLabelsValidation: true,
}
}

Expand Down
16 changes: 12 additions & 4 deletions lib/k8s/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type Config struct {
detachRunner bool
// fundReturnFailed the status of a fund return
fundReturnFailed bool
// Skip validating that all required chain.link labels are present in the final manifest
SkipRequiredChainLinkLabelsValidation bool
}

func defaultEnvConfig() *Config {
Expand Down Expand Up @@ -513,11 +515,13 @@ func (m *Environment) ReplaceHelm(name string, chart ConnectedChart) (*Environme
workloadLabels, err := getComponentLabels(m.Cfg.WorkloadLabels, chart.GetLabels())
if err != nil {
m.err = err
return nil, err
}

podLabels, err := getComponentLabels(m.Cfg.PodLabels, chart.GetLabels())
if err != nil {
m.err = err
return nil, err
}

addRequiredChainLinkLabelsToWorkloads(h, workloadLabels)
Expand Down Expand Up @@ -618,7 +622,7 @@ func (m *Environment) UpdateHelm(name string, values map[string]any) (*Environme
return m.ReplaceHelm(name, chart)
}

// AddHelmCharts adds multiple helm charts to the testing environment
// Charts adds multiple helm charts to the testing environment
func (m *Environment) AddHelmCharts(charts []ConnectedChart) *Environment {
if m.err != nil {
return m
Expand Down Expand Up @@ -674,11 +678,13 @@ func (m *Environment) AddHelm(chart ConnectedChart) *Environment {
workloadLabels, err := getComponentLabels(m.Cfg.WorkloadLabels, chart.GetLabels())
if err != nil {
m.err = err
return m
}

podLabels, err := getComponentLabels(m.Cfg.PodLabels, chart.GetLabels())
if err != nil {
m.err = err
return m
}
addRequiredChainLinkLabelsToWorkloads(h, workloadLabels)
addDefaultPodAnnotationsAndLabels(h, markNotSafeToEvict(m.Cfg.PreventPodEviction, nil), podLabels)
Expand Down Expand Up @@ -865,9 +871,11 @@ func (m *Environment) RunCustomReadyConditions(customCheck *client.ReadyCheckDat
}
log.Debug().Bool("ManifestUpdate", m.Cfg.SkipManifestUpdate).Msg("Update mode")

// make sure all required chain.link labels are present in the final manifest
if err := m.validateRequiredChainLinkLabels(); err != nil {
return err
if !m.Cfg.SkipRequiredChainLinkLabelsValidation {
// make sure all required chain.link labels are present in the final manifest
if err := m.validateRequiredChainLinkLabels(); err != nil {
return err
}
}

if !m.Cfg.SkipManifestUpdate || m.Cfg.JobImage != "" {
Expand Down
9 changes: 6 additions & 3 deletions lib/k8s/pkg/cdk8s/blockscout/blockscout.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func New(props *Props) func(root cdk8s.Chart) environment.ConnectedChart {
}
vars := vars{
Labels: &map[string]*string{
"app": ptr.Ptr(c.GetName()),
"app": ptr.Ptr(c.GetName()),
"chain.link/component": ptr.Ptr("blockscout"),
},
ConfigMapName: fmt.Sprintf("%s-cm", c.GetName()),
BaseName: c.GetName(),
Expand Down Expand Up @@ -117,7 +118,8 @@ type vars struct {
func service(chart cdk8s.Chart, vars vars) {
k8s.NewKubeService(chart, ptr.Ptr(fmt.Sprintf("%s-service", vars.BaseName)), &k8s.KubeServiceProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr(vars.BaseName),
Name: ptr.Ptr(vars.BaseName),
Labels: vars.Labels,
},
Spec: &k8s.ServiceSpec{
Ports: &[]*k8s.ServicePort{
Expand Down Expand Up @@ -173,7 +175,8 @@ func deployment(chart cdk8s.Chart, vars vars) {
ptr.Ptr(fmt.Sprintf("%s-deployment", vars.BaseName)),
&k8s.KubeDeploymentProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr(vars.BaseName),
Name: ptr.Ptr(vars.BaseName),
Labels: vars.Labels,
},
Spec: &k8s.DeploymentSpec{
Selector: &k8s.LabelSelector{
Expand Down
9 changes: 6 additions & 3 deletions lib/k8s/pkg/cdk8s/goc/goc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func New() func(root cdk8s.Chart) environment.ConnectedChart {
c := &Chart{}
vars := vars{
Labels: &map[string]*string{
"app": ptr.Ptr(c.GetName()),
"app": ptr.Ptr(c.GetName()),
"chain.link/component": ptr.Ptr("goc"),
},
ConfigMapName: fmt.Sprintf("%s-cm", c.GetName()),
BaseName: c.GetName(),
Expand Down Expand Up @@ -82,7 +83,8 @@ type vars struct {
func service(chart cdk8s.Chart, vars vars) {
k8s.NewKubeService(chart, ptr.Ptr(fmt.Sprintf("%s-service", vars.BaseName)), &k8s.KubeServiceProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr(vars.BaseName),
Name: ptr.Ptr(vars.BaseName),
Labels: vars.Labels,
},
Spec: &k8s.ServiceSpec{
Ports: &[]*k8s.ServicePort{
Expand All @@ -103,7 +105,8 @@ func deployment(chart cdk8s.Chart, vars vars) {
ptr.Ptr(fmt.Sprintf("%s-deployment", vars.BaseName)),
&k8s.KubeDeploymentProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr(vars.BaseName),
Name: ptr.Ptr(vars.BaseName),
Labels: vars.Labels,
},
Spec: &k8s.DeploymentSpec{
Selector: &k8s.LabelSelector{
Expand Down
9 changes: 6 additions & 3 deletions lib/k8s/pkg/cdk8s/http_dummy/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func New() func(root cdk8s.Chart) environment.ConnectedChart {
c := &Chart{}
vars := vars{
Labels: &map[string]*string{
"app": ptr.Ptr(c.GetName()),
"app": ptr.Ptr(c.GetName()),
"chain.link/component": ptr.Ptr("http_dummy"),
},
ConfigMapName: fmt.Sprintf("%s-cm", c.GetName()),
BaseName: c.GetName(),
Expand Down Expand Up @@ -97,7 +98,8 @@ type vars struct {
func service(chart cdk8s.Chart, vars vars) {
k8s.NewKubeService(chart, ptr.Ptr(fmt.Sprintf("%s-service", vars.BaseName)), &k8s.KubeServiceProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr(vars.BaseName),
Name: ptr.Ptr(vars.BaseName),
Labels: vars.Labels,
},
Spec: &k8s.ServiceSpec{
Ports: &[]*k8s.ServicePort{
Expand All @@ -118,7 +120,8 @@ func deployment(chart cdk8s.Chart, vars vars) {
ptr.Ptr(fmt.Sprintf("%s-deployment", vars.BaseName)),
&k8s.KubeDeploymentProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr(vars.BaseName),
Name: ptr.Ptr(vars.BaseName),
Labels: vars.Labels,
},
Spec: &k8s.DeploymentSpec{
Selector: &k8s.LabelSelector{
Expand Down

0 comments on commit 3dded98

Please sign in to comment.