Skip to content

Commit 6d6ec34

Browse files
Merge pull request #1851 from furkatgofurov7/add-gitea-setup
Add gitea helpers back to e2e setup
2 parents 47030e8 + 36343fa commit 6d6ec34

File tree

9 files changed

+571
-0
lines changed

9 files changed

+571
-0
lines changed

test/e2e/config/operator.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ variables:
108108
NGROK_PATH: "ngrok/ngrok-operator"
109109
NGROK_API_KEY: ""
110110
NGROK_AUTHTOKEN: ""
111+
112+
# Gitea Configuration
113+
GITEA_REPO_NAME: "gitea-charts"
114+
GITEA_REPO_URL: "https://dl.gitea.com/charts/"
115+
GITEA_CHART_NAME: "gitea"
116+
GITEA_CHART_VERSION: "12.4.0"
117+
GITEA_USER_NAME: "gitea_admin"
118+
GITEA_USER_PWD: "password"
111119

112120
# Credentials used to pull images from docker.io
113121
DOCKER_REGISTRY_TOKEN: ""

test/e2e/const.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ var (
136136

137137
//go:embed data/test-providers/clusterctlconfig-updated.yaml
138138
ClusterctlConfigUpdated []byte
139+
140+
//go:embed data/gitea/ingress.yaml
141+
GiteaIngress []byte
142+
143+
//go:embed data/gitea/values.yaml
144+
GiteaValues []byte
139145
)
140146

141147
const (
@@ -191,6 +197,13 @@ const (
191197
CapiClusterOwnerLabel = "cluster-api.cattle.io/capi-cluster-owner"
192198
CapiClusterOwnerNamespaceLabel = "cluster-api.cattle.io/capi-cluster-owner-ns"
193199
OwnedLabelName = "cluster-api.cattle.io/owned"
200+
201+
GiteaRepoNameVar = "GITEA_REPO_NAME"
202+
GiteaRepoURLVar = "GITEA_REPO_URL"
203+
GiteaChartNameVar = "GITEA_CHART_NAME"
204+
GiteaChartVersionVar = "GITEA_CHART_VERSION"
205+
GiteaUserNameVar = "GITEA_USER_NAME"
206+
GiteaUserPasswordVar = "GITEA_USER_PWD"
194207
)
195208

196209
const (

test/e2e/data/gitea/ingress.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: gitea-http
55
namespace: default
66
spec:
7+
ingressClassName: ${GITEA_INGRESS_CLASS_NAME:=ngrok}
78
rules:
89
- host: gitea.${RANCHER_HOSTNAME}
910
http:

test/e2e/data/gitea/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ gitea:
1212
TYPE: level
1313
persistence:
1414
enabled: false
15+
16+
redis-cluster:
17+
enabled: false
1518
postgresql:
1619
enabled: false
1720
postgresql-ha:

test/framework/git_helper.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,133 @@ package framework
1818

1919
import (
2020
"cmp"
21+
"context"
2122
"fmt"
2223
"os"
2324
"strings"
25+
"time"
2426

2527
. "github.com/onsi/gomega"
2628

2729
"github.com/go-git/go-git/v5"
30+
"github.com/go-git/go-git/v5/plumbing/object"
31+
"github.com/go-git/go-git/v5/plumbing/transport/http"
2832
)
2933

34+
// GitCloneRepoInput is the input to GitCloneRepo.
35+
type GitCloneRepoInput struct {
36+
// Address is the URL of the repository to clone.
37+
Address string
38+
39+
// CloneLocation is the directory where the repository will be cloned.
40+
CloneLocation string
41+
42+
// Username is the username for authentication (optional).
43+
Username string `env:"GITEA_USER_NAME"`
44+
45+
// Password is the password for authentication (optional).
46+
Password string `env:"GITEA_USER_PWD"`
47+
}
48+
49+
// GitCloneRepo will clone a repo to a given location.
50+
func GitCloneRepo(ctx context.Context, input GitCloneRepoInput) string {
51+
Expect(Parse(&input)).To(Succeed(), "Failed to parse environment variables")
52+
53+
Expect(ctx).NotTo(BeNil(), "ctx is required for GitCloneRepo")
54+
Expect(input.Address).ToNot(BeEmpty(), "Invalid argument. input.Address can't be empty when calling GitCloneRepo")
55+
56+
cloneDir := input.CloneLocation
57+
58+
if input.CloneLocation == "" {
59+
dir, err := os.MkdirTemp("", "turtles-clone")
60+
Expect(err).ShouldNot(HaveOccurred(), "Failed creating temporary clone directory")
61+
cloneDir = dir
62+
}
63+
64+
opts := &git.CloneOptions{
65+
URL: input.Address,
66+
Progress: os.Stdout,
67+
}
68+
if input.Username != "" {
69+
opts.Auth = &http.BasicAuth{
70+
Username: input.Username,
71+
Password: input.Password,
72+
}
73+
}
74+
75+
_, err := git.PlainClone(cloneDir, false, opts)
76+
Expect(err).ShouldNot(HaveOccurred(), "Failed cloning repo")
77+
78+
return cloneDir
79+
}
80+
81+
// GitCommitAndPushInput is the input to GitCommitAndPush.
82+
type GitCommitAndPushInput struct {
83+
// CloneLocation is the directory where the repository is cloned.
84+
CloneLocation string
85+
86+
// Username is the username for authentication (optional).
87+
Username string `env:"GITEA_USER_NAME"`
88+
89+
// Password is the password for authentication (optional).
90+
Password string `env:"GITEA_USER_PWD"`
91+
92+
// CommitMessage is the message for the commit.
93+
CommitMessage string
94+
95+
// GitPushWait is the wait time for the git push operation.
96+
GitPushWait []interface{} `envDefault:"3m,10s"`
97+
}
98+
99+
// GitCommitAndPush will commit the files for a repo and push the changes to the origin.
100+
func GitCommitAndPush(ctx context.Context, input GitCommitAndPushInput) {
101+
Expect(Parse(&input)).To(Succeed(), "Failed to parse environment variables")
102+
103+
Expect(ctx).NotTo(BeNil(), "ctx is required for GitCommitAndPush")
104+
Expect(input.CloneLocation).ToNot(BeEmpty(), "Invalid argument. input.CloneLoaction can't be empty when calling GitCommitAndPush")
105+
Expect(input.CommitMessage).ToNot(BeEmpty(), "Invalid argument. input.CommitMessage can't be empty when calling GitCommitAndPush")
106+
107+
repo, err := git.PlainOpen(input.CloneLocation)
108+
Expect(err).ShouldNot(HaveOccurred(), "Failed opening the repo")
109+
110+
tree, err := repo.Worktree()
111+
Expect(err).ShouldNot(HaveOccurred(), "Failed getting work tree for repo")
112+
113+
err = tree.AddWithOptions(&git.AddOptions{
114+
All: true,
115+
})
116+
Expect(err).ShouldNot(HaveOccurred(), "Failed adding all files")
117+
118+
commitOptions := &git.CommitOptions{
119+
Author: &object.Signature{
120+
Name: "Rancher Turtles Tests",
121+
122+
When: time.Now(),
123+
},
124+
}
125+
126+
_, err = tree.Commit(input.CommitMessage, commitOptions)
127+
Expect(err).ShouldNot(HaveOccurred(), "Failed to commit files")
128+
129+
pushOptions := &git.PushOptions{}
130+
if input.Username != "" {
131+
pushOptions.Auth = &http.BasicAuth{
132+
Username: input.Username,
133+
Password: input.Password,
134+
}
135+
}
136+
err = repo.Push(pushOptions)
137+
Expect(err).ShouldNot(HaveOccurred(), "Failed pushing changes")
138+
139+
Eventually(func() error {
140+
err := repo.Push(pushOptions)
141+
if err.Error() == "already up-to-date" {
142+
return nil
143+
}
144+
return err
145+
}, input.GitPushWait...).Should(Succeed(), "Failed to connect to workload cluster using CAPI kubeconfig")
146+
}
147+
30148
// defaultToCurrentGitRepo retrieves the repository URL and the current branch
31149
func defaultToCurrentGitRepo(input *FleetCreateGitRepoInput) {
32150
if input.Repo != "" {

test/framework/gitea_helper.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright © 2023 - 2024 SUSE LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package framework
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
. "github.com/onsi/gomega"
24+
25+
"code.gitea.io/sdk/gitea"
26+
)
27+
28+
// GiteaCreateRepoInput represents the input parameters for creating a repository in Gitea.
29+
type GiteaCreateRepoInput struct {
30+
// ServerAddr is the address of the Gitea server.
31+
ServerAddr string
32+
33+
// RepoName is the name of the repository to be created.
34+
RepoName string
35+
36+
// Username is the username of the user creating the repository.
37+
Username string `env:"GITEA_USER_NAME"`
38+
39+
// Password is the password of the user creating the repository.
40+
Password string `env:"GITEA_USER_PWD"`
41+
}
42+
43+
// GiteaCreateRepo will create a new repo in the Gitea server.
44+
func GiteaCreateRepo(ctx context.Context, input GiteaCreateRepoInput) string {
45+
Expect(Parse(&input)).To(Succeed(), "Failed to parse environment variables")
46+
47+
Expect(ctx).NotTo(BeNil(), "ctx is required for GiteaCreateRepo")
48+
Expect(input.ServerAddr).ToNot(BeEmpty(), "Invalid argument. input.ServerAddr can't be empty when calling GiteaCreateRepo")
49+
Expect(input.RepoName).ToNot(BeEmpty(), "Invalid argument. input.RepoName can't be empty when calling GiteaCreateRepo")
50+
Expect(input.Username).ToNot(BeEmpty(), "Invalid argument. input.Username can't be empty when calling GiteaCreateRepo")
51+
Expect(input.Password).ToNot(BeEmpty(), "Invalid argument. input.Password can't be empty when calling GiteaCreateRepo")
52+
53+
opts := []gitea.ClientOption{
54+
gitea.SetBasicAuth(input.Username, input.Password),
55+
gitea.SetContext(ctx),
56+
}
57+
58+
client, err := gitea.NewClient(input.ServerAddr, opts...)
59+
Expect(err).ShouldNot(HaveOccurred())
60+
61+
repo, _, err := client.CreateRepo(gitea.CreateRepoOption{
62+
Name: input.RepoName,
63+
AutoInit: true,
64+
})
65+
Expect(err).ShouldNot(HaveOccurred())
66+
67+
return fmt.Sprintf("%s/%s.git", input.ServerAddr, repo.FullName)
68+
}

test/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ require (
2626
sigs.k8s.io/kind v0.30.0
2727
)
2828

29+
require (
30+
github.com/42wim/httpsig v1.2.3 // indirect
31+
github.com/davidmz/go-pageant v1.0.2 // indirect
32+
github.com/go-fed/httpsig v1.1.0 // indirect
33+
github.com/hashicorp/go-version v1.7.0 // indirect
34+
)
35+
2936
require (
3037
al.essio.dev/pkg/shellescape v1.5.1 // indirect
3138
cel.dev/expr v0.20.0 // indirect
39+
code.gitea.io/sdk/gitea v0.22.1
3240
github.com/BurntSushi/toml v1.4.0 // indirect
3341
github.com/MakeNowJust/heredoc v1.0.0 // indirect
3442
github.com/Masterminds/goutils v1.1.1 // indirect

test/go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ al.essio.dev/pkg/shellescape v1.5.1 h1:86HrALUujYS/h+GtqoB26SBEdkWfmMI6FubjXlsXy
22
al.essio.dev/pkg/shellescape v1.5.1/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWtls1U8I890=
33
cel.dev/expr v0.20.0 h1:OunBvVCfvpWlt4dN7zg3FM6TDkzOePe1+foGJ9AXeeI=
44
cel.dev/expr v0.20.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
5+
code.gitea.io/sdk/gitea v0.22.1 h1:7K05KjRORyTcTYULQ/AwvlVS6pawLcWyXZcTr7gHFyA=
6+
code.gitea.io/sdk/gitea v0.22.1/go.mod h1:yyF5+GhljqvA30sRDreoyHILruNiy4ASufugzYg0VHM=
57
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
68
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
9+
github.com/42wim/httpsig v1.2.3 h1:xb0YyWhkYj57SPtfSttIobJUPJZB9as1nsfo7KWVcEs=
10+
github.com/42wim/httpsig v1.2.3/go.mod h1:nZq9OlYKDrUBhptd77IHx4/sZZD+IxTBADvAPI9G/EM=
711
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
812
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
913
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
@@ -62,6 +66,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
6266
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6367
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
6468
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
69+
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
70+
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
6571
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
6672
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
6773
github.com/docker/docker v28.0.2+incompatible h1:9BILleFwug5FSSqWBgVevgL3ewDJfWWWyZVqlDMttE8=
@@ -100,6 +106,8 @@ github.com/gkampitakis/go-snaps v0.5.15 h1:amyJrvM1D33cPHwVrjo9jQxX8g/7E2wYdZ+01
100106
github.com/gkampitakis/go-snaps v0.5.15/go.mod h1:HNpx/9GoKisdhw9AFOBT1N7DBs9DiHo/hGheFGBZ+mc=
101107
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
102108
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
109+
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
110+
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
103111
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
104112
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
105113
github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM=
@@ -165,6 +173,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
165173
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
166174
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
167175
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
176+
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
177+
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
168178
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
169179
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
170180
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
@@ -361,6 +371,7 @@ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
361371
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
362372
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
363373
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
374+
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
364375
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
365376
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
366377
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
@@ -374,6 +385,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
374385
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
375386
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
376387
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
388+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
377389
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
378390
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
379391
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=

0 commit comments

Comments
 (0)