Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit ed0c1cd

Browse files
committed
adding more refactoring and unit tests
1 parent 6604de7 commit ed0c1cd

File tree

7 files changed

+421
-63
lines changed

7 files changed

+421
-63
lines changed

.github/workflows/gotest-cover.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: golangci-lint
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
# Remove all permissions from GH_TOKEN except metadata.
8+
permissions: {}
9+
10+
jobs:
11+
golangci:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
working-directory:
17+
- ""
18+
steps:
19+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # tag=v4.1.6
20+
- name: Calculate go version
21+
id: vars
22+
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
23+
- name: Set up Go
24+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag=v5.5.0
25+
with:
26+
go-version: ${{ steps.vars.outputs.go_version }}
27+
- name: Go Tests with coverage
28+
run: |
29+
make test-cover

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ CAPI_KIND_CLUSTER_NAME ?= capi-test
230230

231231
# It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971
232232

233-
# Next release is: v0.3.2
234-
TAG ?= v0.3.2-preview.53
233+
# Next release is: v1.0.0-preview
234+
TAG ?= v1.0.0-preview
235235
ARCH ?= $(shell go env GOARCH)
236236
ALL_ARCH = amd64 arm arm64
237237

config/default/manager_image_patch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ spec:
77
template:
88
spec:
99
containers:
10-
- image: ghcr.io/patricklaabs/cluster-api-addon-provider-cdk8s/cluster-api-cdk8s-controller:v0.3.2-preview.53
10+
- image: ghcr.io/patricklaabs/cluster-api-addon-provider-cdk8s/cluster-api-cdk8s-controller:v1.0.0-preview
1111
name: manager

config/default/manager_image_patch.yaml-e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ spec:
77
template:
88
spec:
99
containers:
10-
- image: ghcr.io/patricklaabs/cluster-api-addon-provider-cdk8s/cluster-api-cdk8s-controller:v0.3.2-preview.53
10+
- image: ghcr.io/patricklaabs/cluster-api-addon-provider-cdk8s/cluster-api-cdk8s-controller:v1.0.0-preview
1111
name: manager

controllers/cdk8sappproxy/cdk8sappproxy_git_operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (r *Reconciler) prepareSource(ctx context.Context, cdk8sAppProxy *addonsv1a
3535
logger.Error(err, addonsv1alpha1.GitCloneFailedCondition, "Failed to clone git repository")
3636
}
3737

38-
retrieveCommitHash, err := gitImpl.Hash(tempDir)
38+
retrieveCommitHash, err := gitImpl.Hash(tempDir, cdk8sAppProxy.Spec.GitRepository.Reference)
3939
if err != nil {
4040
logger.Error(err, addonsv1alpha1.GitHashFailureReason, "Failed to get local git hash")
4141
}

controllers/cdk8sappproxy/git/git.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type GitOperator interface {
1515
Clone(repoUrl string, directory string, writer *bytes.Buffer) (err error)
1616
Poll(repo string, branch string, directory string, writer *bytes.Buffer) (changes bool, err error)
17-
Hash(repo string) (hash string, err error)
17+
Hash(repo string, branch string) (hash string, err error)
1818
}
1919

2020
// GitImplementer implements the GitOperator interface.
@@ -54,15 +54,15 @@ func (g *GitImplementer) Poll(repo string, branch string, directory string, writ
5454
}
5555

5656
// Get hash from local repo.
57-
localHash, err := g.Hash(directory)
57+
localHash, err := g.Hash(directory, branch)
5858
if err != nil {
5959
fmt.Fprintf(writer, "localGitHash error")
6060

6161
return changes, err
6262
}
6363

6464
// Get Hash from remote repo
65-
remoteHash, err := g.Hash(repo)
65+
remoteHash, err := g.Hash(repo, branch)
6666
if err != nil {
6767
fmt.Fprintf(writer, "remoteGitHash error")
6868

@@ -79,11 +79,7 @@ func (g *GitImplementer) Poll(repo string, branch string, directory string, writ
7979
}
8080

8181
// Hash retrieves the hash of the given repository.
82-
func (g *GitImplementer) Hash(repo string) (hash string, err error) {
83-
//cdk8sAppProxy := &addonsv1alpha1.Cdk8sAppProxy{}
84-
//branch := cdk8sAppProxy.Spec.GitRepository.Reference
85-
branch := "main"
86-
82+
func (g *GitImplementer) Hash(repo string, branch string) (hash string, err error) {
8783
switch {
8884
case isUrl(repo):
8985
remoterepo := git.NewRemote(nil, &config.RemoteConfig{

0 commit comments

Comments
 (0)