Skip to content

Commit

Permalink
Add test target and upgrade libgit2 (#17927)
Browse files Browse the repository at this point in the history
* add testenv

* upgrade git2go

* bump image and update docs

* update dockerfiles

* remove trash

* update job init
  • Loading branch information
dbadura authored Aug 7, 2023
1 parent b8b7404 commit be146f1
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 30 deletions.
3 changes: 2 additions & 1 deletion components/function-controller/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
!go.mod
!go.sum
!licenses
!vendor
!vendor
bin
2 changes: 1 addition & 1 deletion components/function-controller/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ vendor/
*~

cover.out

filered.cov
log_config.yaml
21 changes: 21 additions & 0 deletions components/function-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,24 @@ else
@echo "Image signing skipped"
endif


# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)


########## Envtest ###########
ENVTEST ?= $(LOCALBIN)/setup-envtest

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: test
test: envtest
KUBEBUILDER_CONTROLPLANE_START_TIMEOUT=2m KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT=2m KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./...
4 changes: 2 additions & 2 deletions components/function-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The Function Controller requires the following components to be installed:
## Development

To develop the Function Controller, you need:
- [libgit2-dev](https://libgit2.org/) (v1.1)
- [libgit2-dev](https://libgit2.org/) (v1.5)
- [controller-gen](https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.6.2) (v0.6.2)
- [kustomize](https://github.com/kubernetes-sigs/kustomize/releases/tag/kustomize%2Fv4.5.7) (v4.5.7)

Expand Down Expand Up @@ -93,7 +93,7 @@ Build and install the libgit2 binary required by the Function Controller on macO
```bash
github.com/libgit2/git2go/v31 v31.4.14
```
2. Go to the [git2go page](https://github.com/libgit2/git2go#git2go) to check which version of libgit2 you must use. For example, for git2go v31, use libigit2 in version 1.1.
2. Go to the [git2go page](https://github.com/libgit2/git2go#git2go) to check which version of libgit2 you must use. For example, for git2go v34, use libigit2 in version 1.5.

3. Clone the `libgit2` repository:

Expand Down
8 changes: 4 additions & 4 deletions components/function-controller/deploy/jobinit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ ENV BASE_APP_DIR=/workspace/go/src/github.com/kyma-project/kyma/components/funct
CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
LIBGIT2_VERSION=1.1.0-r2
LIBGIT2_VERSION=1.5.2-r0

RUN apk add --no-cache gcc libc-dev
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.14/community libgit2-dev=${LIBGIT2_VERSION}
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.18/community libgit2-dev=${LIBGIT2_VERSION}

WORKDIR ${BASE_APP_DIR}

Expand All @@ -23,14 +23,14 @@ RUN go build -ldflags "-s -w" -a -o jobinit cmd/jobinit/main.go \

# result container base on alpine:3.17.4
FROM europe-docker.pkg.dev/kyma-project/prod/external/alpine@sha256:e95676db9e4a4f16f6cc01a8915368f82b018cc07aba951c1bd1db586c081388
ENV LIBGIT2_VERSION=1.1.0-r2
ENV LIBGIT2_VERSION=1.5.2-r0

LABEL source = [email protected]:kyma-project/kyma.git

RUN apk update --no-cache && apk upgrade --no-cache
RUN apk add --no-cache ca-certificates
RUN apk add --no-cache --update --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main openssh-client openssl
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.14/community libgit2=${LIBGIT2_VERSION}
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.18/community libgit2=${LIBGIT2_VERSION}

COPY --from=builder /app /app

Expand Down
8 changes: 4 additions & 4 deletions components/function-controller/deploy/manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ ENV BASE_APP_DIR=/workspace/go/src/github.com/kyma-project/kyma/components/funct
CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
LIBGIT2_VERSION=1.1.0-r2
LIBGIT2_VERSION=1.5.2-r0

RUN apk add --no-cache gcc libc-dev
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.14/community libgit2-dev=${LIBGIT2_VERSION}
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.18/community libgit2-dev=${LIBGIT2_VERSION}

WORKDIR ${BASE_APP_DIR}

Expand All @@ -29,11 +29,11 @@ RUN apk add --no-cache ca-certificates
# result container base on alpine:3.17.4
FROM europe-docker.pkg.dev/kyma-project/prod/external/alpine@sha256:e95676db9e4a4f16f6cc01a8915368f82b018cc07aba951c1bd1db586c081388

ENV LIBGIT2_VERSION=1.1.0-r2
ENV LIBGIT2_VERSION=1.5.2-r0

RUN apk update --no-cache && apk upgrade --no-cache
RUN apk add --no-cache --update --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main openssl
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.14/community libgit2=${LIBGIT2_VERSION}
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.18/community libgit2=${LIBGIT2_VERSION}

LABEL source = [email protected]:kyma-project/kyma.git

Expand Down
2 changes: 1 addition & 1 deletion components/function-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/fsnotify/fsnotify v1.5.1
github.com/go-logr/zapr v1.2.0
github.com/kyma-project/kyma/common/logging v0.0.0-20221208072023-1c1502074930
github.com/libgit2/git2go/v31 v31.7.9
github.com/libgit2/git2go/v34 v34.0.0
github.com/onsi/gomega v1.17.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.1
Expand Down
4 changes: 2 additions & 2 deletions components/function-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kyma-project/kyma/common/logging v0.0.0-20221208072023-1c1502074930 h1:lX7bKUOWIGBVqvHmbGbEwYhprZJHICPqj0BCImDc6fM=
github.com/kyma-project/kyma/common/logging v0.0.0-20221208072023-1c1502074930/go.mod h1:JGb5RBi8Uz+RZ/jf54+qA+RqY6uPQBJ8pO1w3KSwm1Q=
github.com/libgit2/git2go/v31 v31.7.9 h1:RUDiYm7+i3GY414acI31oDD8x5P0PZyWeZZfwpPuynE=
github.com/libgit2/git2go/v31 v31.7.9/go.mod h1:c/rkJcBcUFx6wHaT++UwNpKvIsmPNqCeQ/vzO4DrEec=
github.com/libgit2/git2go/v34 v34.0.0 h1:UKoUaKLmiCRbOCD3PtUi2hD6hESSXzME/9OUZrGcgu8=
github.com/libgit2/git2go/v34 v34.0.0/go.mod h1:blVco2jDAw6YTXkErMMqzHLcAjKkwF0aWIRHBqiJkZ0=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/stretchr/testify/mock"

git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"

"github.com/kyma-project/kyma/components/function-controller/internal/controllers/serverless/automock"
"github.com/kyma-project/kyma/components/function-controller/internal/git"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
"github.com/stretchr/testify/assert"
ctrl "sigs.k8s.io/controller-runtime"

Expand Down
8 changes: 4 additions & 4 deletions components/function-controller/internal/git/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
)
Expand Down Expand Up @@ -97,9 +97,9 @@ func authBasicCallback(username, password string) func(url, username string, all
}
}

func sshCheckCallback() func(cert *git2go.Certificate, valid bool, hostname string) git2go.ErrorCode {
return func(cert *git2go.Certificate, valid bool, hostname string) git2go.ErrorCode {
return git2go.ErrOk
func sshCheckCallback() func(cert *git2go.Certificate, valid bool, hostname string) error {
return func(cert *git2go.Certificate, valid bool, hostname string) error {
return nil
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/function-controller/internal/git/cloner.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package git

import (
git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
)

type git2goCloner struct {
}

func (g *git2goCloner) git2goClone(url, outputPath string, remoteCallbacks git2go.RemoteCallbacks) (*git2go.Repository, error) {
return git2go.Clone(url, outputPath, &git2go.CloneOptions{
FetchOptions: &git2go.FetchOptions{
FetchOptions: git2go.FetchOptions{
RemoteCallbacks: remoteCallbacks,
DownloadTags: git2go.DownloadTagsAll,
},
Expand Down
2 changes: 1 addition & 1 deletion components/function-controller/internal/git/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package git
import (
"errors"

git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
)

// Unrecoverable means that something is wrong with configuration of git function CR
Expand Down
2 changes: 1 addition & 1 deletion components/function-controller/internal/git/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package git
import (
"testing"

git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion components/function-controller/internal/git/fetcher.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package git

import (
git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
"github.com/pkg/errors"
"go.uber.org/zap"
)
Expand Down
2 changes: 1 addition & 1 deletion components/function-controller/internal/git/go2git.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"
"strings"

git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
"github.com/pkg/errors"
"go.uber.org/zap"
)
Expand Down
2 changes: 1 addition & 1 deletion components/function-controller/internal/git/go2git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"

git2go "github.com/libgit2/git2go/v31"
git2go "github.com/libgit2/git2go/v34"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand Down
4 changes: 2 additions & 2 deletions resources/serverless/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ global:
directory: "prod"
function_controller:
name: "function-controller"
version: "v20230628-61d97068"
directory: "prod"
version: "PR-17927"
directory: "dev"
function_webhook:
name: "function-webhook"
version: "v20230628-61d97068"
Expand Down

0 comments on commit be146f1

Please sign in to comment.