Skip to content

Commit b3a102e

Browse files
committed
ci: preparation of go code decoupling
1 parent c378e32 commit b3a102e

23 files changed

+230
-247
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
kubeconfig
44
hosts.yml
55
vendor/*
6-
tls.crt
7-
tls.key
8-
public-key-cert.pem
9-
**/kind-logs
6+
*.crt
7+
*.key
8+
*.pem
9+
**/kind-logs

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module test
1+
module e2eutils
22

33
go 1.24.0
44

test/pkg/api/api.go renamed to pkg/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package api
1+
package e2eutils
22

33
import (
44
"context"
55
"errors"
6+
67
appsv1 "k8s.io/api/apps/v1"
78
corev1 "k8s.io/api/core/v1"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -12,7 +13,6 @@ import (
1213
"k8s.io/client-go/dynamic"
1314
"k8s.io/client-go/kubernetes"
1415
"sigs.k8s.io/e2e-framework/klient/k8s"
15-
"test/test/pkg/test"
1616
)
1717

1818
func Apply(clientset kubernetes.Clientset, object runtime.Object) error {
@@ -33,7 +33,7 @@ func Apply(clientset kubernetes.Clientset, object runtime.Object) error {
3333
_, err := createPersistentVolumeClaim(clientset, *object.(*corev1.PersistentVolumeClaim))
3434
return err
3535
case *unstructured.Unstructured:
36-
dynClient, err := test.GetDynClient()
36+
dynClient, err := GetDynClient()
3737
if err != nil {
3838
return err
3939
}
@@ -75,7 +75,7 @@ func createPersistentVolumeClaim(clientset kubernetes.Clientset, object corev1.P
7575
}
7676

7777
func getResourceName(object unstructured.Unstructured) (string, error) {
78-
discoveryClient, err := test.GetDiscoveryClient()
78+
discoveryClient, err := GetDiscoveryClient()
7979
if err != nil {
8080
return "", errors.New("Failed to get discovery client " + err.Error())
8181
}
File renamed without changes.

test/pkg/argo/argo.go renamed to pkg/argo/argo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"io"
66
"net/http"
77
"os"
8-
"sigs.k8s.io/yaml"
98
"strconv"
109
"strings"
10+
11+
"sigs.k8s.io/yaml"
1112
)
1213

1314
func GetArgoApplication(applicationYaml string) (Application, error) {

pkg/client.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package e2eutils
2+
3+
import (
4+
"k8s.io/client-go/discovery"
5+
"k8s.io/client-go/dynamic"
6+
"k8s.io/client-go/kubernetes"
7+
"k8s.io/client-go/rest"
8+
"sigs.k8s.io/e2e-framework/klient"
9+
"sigs.k8s.io/e2e-framework/pkg/envconf"
10+
)
11+
12+
func GetClient() klient.Client {
13+
cfg := envconf.Config{}
14+
return cfg.Client()
15+
}
16+
17+
func GetRestConfig() *rest.Config {
18+
client := GetClient()
19+
return client.RESTConfig()
20+
}
21+
22+
func GetClientSet() (*kubernetes.Clientset, error) {
23+
kubeConfig := GetRestConfig()
24+
clientSet, err := kubernetes.NewForConfig(kubeConfig)
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
return clientSet, nil
30+
}
31+
32+
func GetDynClient() (*dynamic.DynamicClient, error) {
33+
kubeConfig := GetRestConfig()
34+
return dynamic.NewForConfig(kubeConfig)
35+
}
36+
37+
func GetDiscoveryClient() (*discovery.DiscoveryClient, error) {
38+
kubeConfig := GetRestConfig()
39+
return discovery.NewDiscoveryClientForConfig(kubeConfig)
40+
}

test/pkg/git/git.go renamed to pkg/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package git
1+
package e2eutils
22

33
import (
44
"os/exec"

test/pkg/helm/helm.go renamed to pkg/helm.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
package helm
1+
package e2eutils
22

33
import (
4+
"e2eutils/pkg/argo"
45
"fmt"
56
"os"
6-
"sigs.k8s.io/e2e-framework/third_party/helm"
77
"strings"
8-
"test/test/pkg/argo"
8+
9+
"sigs.k8s.io/e2e-framework/third_party/helm"
910
)
1011

1112
type HelmOptions struct {
@@ -34,7 +35,7 @@ func AddHelmRepository(helmMgr *helm.Manager, helmRepoUrl string, helmChartName
3435
return nil
3536
}
3637

37-
func helmifyApp(app argo.ApplicationSource, namespace string) (HelmOptions, error) {
38+
func helmifyArgoApp(app argo.ApplicationSource, namespace string) (HelmOptions, error) {
3839
fullChartName := getFullChartName(app.Chart, app.Chart)
3940
helmOciRepository := ""
4041

@@ -90,7 +91,7 @@ func helmValuesToFile(applicationSource argo.ApplicationSource) error {
9091
}
9192

9293
func DeployHelmChart(helmMgr *helm.Manager, applicationSource argo.ApplicationSource, namespace string) error {
93-
helmOptions, err := helmifyApp(applicationSource, namespace)
94+
helmOptions, err := helmifyArgoApp(applicationSource, namespace)
9495
if err != nil {
9596
return err
9697
}

test/pkg/manifest/manifest.go renamed to pkg/kustomize.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
package manifest
1+
package e2eutils
22

33
import (
44
"context"
5+
"e2eutils/pkg/argo"
56
"os"
7+
"strings"
8+
69
"sigs.k8s.io/e2e-framework/klient/decoder"
710
"sigs.k8s.io/e2e-framework/klient/k8s"
811
"sigs.k8s.io/kustomize/api/krusty"
912
"sigs.k8s.io/kustomize/kyaml/filesys"
10-
"strings"
11-
"test/test/pkg/argo"
1213
)
1314

1415
func GetKubernetesManifests(argoApplication argo.Application) ([]k8s.Object, error) {

test/pkg/test/test.go renamed to pkg/test.go

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
package test
1+
package e2eutils
22

33
import (
44
"context"
5+
"e2eutils/pkg/argo"
56
"errors"
7+
"log/slog"
8+
"reflect"
9+
"strings"
10+
"time"
11+
612
snapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
713
appsv1 "k8s.io/api/apps/v1"
814
corev1 "k8s.io/api/core/v1"
915
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1016
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1117
"k8s.io/apimachinery/pkg/runtime"
1218
"k8s.io/apimachinery/pkg/runtime/schema"
13-
"k8s.io/client-go/discovery"
1419
"k8s.io/client-go/dynamic"
1520
"k8s.io/client-go/kubernetes"
16-
"k8s.io/client-go/rest"
17-
"log/slog"
18-
"reflect"
1921
"sigs.k8s.io/e2e-framework/klient"
2022
"sigs.k8s.io/e2e-framework/klient/k8s"
2123
"sigs.k8s.io/e2e-framework/klient/wait"
2224
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
23-
"sigs.k8s.io/e2e-framework/pkg/envconf"
24-
"strings"
25-
"test/test/pkg/argo"
26-
"test/test/pkg/git"
27-
"test/test/pkg/helm"
28-
"test/test/pkg/manifest"
29-
"time"
3025
)
3126

32-
func PrepareTest(gitRepository string, applicationYaml string) (argo.Application, argo.Application, []k8s.Object, error) {
33-
currGitBranch, err := git.GetCurrentGitBranch()
27+
func PrepareArgoApp(gitRepository string, applicationYaml string) (argo.Application, argo.Application, []k8s.Object, error) {
28+
currGitBranch, err := GetCurrentGitBranch()
3429
if err != nil {
3530
return argo.Application{}, argo.Application{}, nil, err
3631
}
@@ -41,7 +36,7 @@ func PrepareTest(gitRepository string, applicationYaml string) (argo.Application
4136
return argo.Application{}, argo.Application{}, nil, err
4237
}
4338

44-
objects, err := manifest.GetKubernetesManifests(current)
39+
objects, err := GetKubernetesManifests(current)
4540
if err != nil {
4641
return current, argo.Application{}, nil, err
4742
}
@@ -54,7 +49,7 @@ func PrepareTest(gitRepository string, applicationYaml string) (argo.Application
5449
return argo.Application{}, argo.Application{}, nil, err
5550
}
5651

57-
objects, err := manifest.GetKubernetesManifests(update)
52+
objects, err := GetKubernetesManifests(update)
5853
if err != nil {
5954
return argo.Application{}, argo.Application{}, nil, err
6055
}
@@ -78,16 +73,16 @@ func PrepareTest(gitRepository string, applicationYaml string) (argo.Application
7873
}
7974

8075
func deployHelmChart(applicationSource argo.ApplicationSource, namespace string, kubeConfigFile string) error {
81-
helmMgr := helm.GetHelmManager(kubeConfigFile)
76+
helmMgr := GetHelmManager(kubeConfigFile)
8277

8378
if !strings.Contains(applicationSource.RepoURL, "oci://") {
84-
err := helm.AddHelmRepository(helmMgr, applicationSource.RepoURL, applicationSource.Chart)
79+
err := AddHelmRepository(helmMgr, applicationSource.RepoURL, applicationSource.Chart)
8580
if err != nil {
8681
return err
8782
}
8883
}
8984

90-
err := helm.DeployHelmChart(helmMgr, applicationSource, namespace)
85+
err := DeployHelmChart(helmMgr, applicationSource, namespace)
9186
if err != nil {
9287
return err
9388
}
@@ -124,36 +119,6 @@ func DeployHelmCharts(kubeConfigFile string, argoApplication argo.Application) e
124119
return nil
125120
}
126121

127-
func GetClient() (klient.Client, error) {
128-
cfg := envconf.Config{}
129-
return cfg.Client(), nil
130-
}
131-
132-
func GetRestConfig() *rest.Config {
133-
client, _ := GetClient()
134-
return client.RESTConfig()
135-
}
136-
137-
func GetClientSet() (*kubernetes.Clientset, error) {
138-
kubeConfig := GetRestConfig()
139-
clientSet, err := kubernetes.NewForConfig(kubeConfig)
140-
if err != nil {
141-
return nil, err
142-
}
143-
144-
return clientSet, nil
145-
}
146-
147-
func GetDynClient() (*dynamic.DynamicClient, error) {
148-
kubeConfig := GetRestConfig()
149-
return dynamic.NewForConfig(kubeConfig)
150-
}
151-
152-
func GetDiscoveryClient() (*discovery.DiscoveryClient, error) {
153-
kubeConfig := GetRestConfig()
154-
return discovery.NewDiscoveryClientForConfig(kubeConfig)
155-
}
156-
157122
func CheckJobsCompleted(ctx context.Context, client klient.Client, namespace string) error {
158123
kubeConfig := client.RESTConfig()
159124
clientSet, err := kubernetes.NewForConfig(kubeConfig)

0 commit comments

Comments
 (0)