Skip to content

test/test-framework: add go.mod, go.sum and build/Dockerfile #2202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions doc/dev/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ $ git checkout -b release-v1.3.0
Commit the following changes:

- `version/version.go`: update `Version` to `v1.3.0`.
- `internal/scaffold/go_mod.go`, in the `require` block for `github.com/operator-framework/operator-sdk`:
- Change the version for `github.com/operator-framework/operator-sdk` from `master` to `v1.3.0`.
- `internal/scaffold/go_mod.go`, change the `require` line version for `github.com/operator-framework/operator-sdk` from `master` to `v1.3.0`.
- `internal/scaffold/helm/go_mod.go`: same as for `internal/scaffold/go_mod.go`.
- `internal/scaffold/ansible/go_mod.go`: same as for `internal/scaffold/go_mod.go`.
- `test/test-framework/go.mod`: change the `require` line version for `github.com/operator-framework/operator-sdk` from its current version to `v1.3.0`.
- `CHANGELOG.md`: update the `## Unreleased` header to `## v1.3.0`.
- `doc/user/install-operator-sdk.md`: update the linux and macOS URLs to point to the new release URLs.

Expand Down Expand Up @@ -236,8 +236,7 @@ Once this tag passes CI, go to step 3. For more info on tagging, see the [releas
Check out a new branch from master (or use your `release-v1.3.0` branch) and commit the following changes:

- `version/version.go`: update `Version` to `v1.3.0+git`.
- `internal/scaffold/go_mod.go`, in the `require` block for `github.com/operator-framework/operator-sdk`:
- Change the version for `github.com/operator-framework/operator-sdk` from `v1.3.0` to `master`.
- `internal/scaffold/go_mod.go`, change the `require` line version for `github.com/operator-framework/operator-sdk` from `v1.3.0` to `master`.
- `internal/scaffold/helm/go_mod.go`: same as for `internal/scaffold/go_mod.go`.
- `internal/scaffold/ansible/go_mod.go`: same as for `internal/scaffold/go_mod.go`.
- `CHANGELOG.md`: add the following as a new set of headers above `## v1.3.0`:
Expand Down
23 changes: 11 additions & 12 deletions hack/generate/gen-test-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ set -ex

source hack/lib/test_lib.sh

# Define vars
DOCKERFILE="build/Dockerfile"

# Go inside of the mock data test project
cd test/test-framework

# Create the required files in the mock test/test-framework just to allow run from it the oprator-sdk commands
echo > $DOCKERFILE
go mod init test-framework

# Remove files that are required and created just to exec the commands.
trap_add 'rm -rf $DOCKERFILE go.mod go.sum' EXIT
# Ensure test-framework is up-to-date with current Go project dependencies.
# NOTE: the SDK dependency version still needs updating on a new release.
sdk_version="$(go list -m -f '{{.Version}}' github.com/operator-framework/operator-sdk)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about this command! If there's equivalent go code, maybe in a future PR, we should consider outputting this version in the go.mod scaffold directly. Though maybe it's moot with the kubebuilder transition.

../../build/operator-sdk print-deps > go.mod
sed -i 's|github.com/operator-framework/operator-sdk\s*master||g' go.mod
echo -e "\nreplace github.com/operator-framework/operator-sdk => ../../" >> go.mod
go mod edit -require "github.com/operator-framework/operator-sdk@${sdk_version}"
go build ./...
go mod tidy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does go.sum need to be checked in? If so, maybe we should run go mod tidy in this script to make it easier to keep up-to-date?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tidy is already run in sanity-check.sh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that helps us. Does go mod tidy run recursively against all other modules (e.g. test/test-framework) in the repo? I don't think it does.

If we include it here, a developer can run make gen-test-framework after making changes in the test framework to pick up all of the necessary changes. go.mod and go.sum will get updated along with the other generated files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see what you mean. It does not. I will add it here.

# Run gen commands
../../build/operator-sdk generate k8s
../../build/operator-sdk generate openapi

# TODO(camilamacedo86): remove this when the openapi gen be set to false and it no longer is generated
# The following file is gen by openapi but it has not been committed in order to allow we clone and call the test locally in any path.
trap_add 'rm pkg/apis/cache/v1alpha1/zz_generated.openapi.go' EXIT
trap_add 'rm pkg/apis/cache/v1alpha1/zz_generated.openapi.go' EXIT
../../build/operator-sdk generate openapi
10 changes: 10 additions & 0 deletions internal/scaffold/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package scaffold

import (
"bytes"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -112,6 +113,15 @@ func (s *CRD) CustomRender() ([]byte, error) {
}
return nil, err
}
// Until we bump dependencies to Kubernetes v1.16, generated validation
// descriptions for kind and apiVersion will contain an invalid link.
// Manually replace them here.
//
// TODO(estroz): remove on k8s v1.16 bump.
b = bytes.ReplaceAll(b,
[]byte("https://git.k8s.io/community/contributors/devel/api-conventions.md"),
[]byte("https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md"),
)
if err = yaml.Unmarshal(b, crd); err != nil {
return nil, err
}
Expand Down
14 changes: 12 additions & 2 deletions internal/scaffold/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package scaffold

import (
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -42,6 +43,15 @@ func TestCRDGoProject(t *testing.T) {
t.Fatal(err)
}

// Must change directories since the test framework dir is a sub-module.
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
defer func() { os.Chdir(wd) }()
if err = os.Chdir(cfg.AbsProjectPath); err != nil {
t.Fatal(err)
}
err = s.Execute(cfg, &CRD{Resource: r, IsOperatorGo: true})
if err != nil {
t.Fatalf("Failed to execute the scaffold: (%v)", err)
Expand Down Expand Up @@ -74,12 +84,12 @@ spec:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand Down
15 changes: 15 additions & 0 deletions test/test-framework/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ENV OPERATOR=/usr/local/bin/memcached-operator \
USER_UID=1001 \
USER_NAME=test-framework

# install operator binary
COPY build/_output/bin/test-framework ${OPERATOR}

COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup

ENTRYPOINT ["/usr/local/bin/entrypoint"]

USER ${USER_UID}
38 changes: 38 additions & 0 deletions test/test-framework/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module github.com/operator-framework/operator-sdk/test/test-framework

go 1.13

require (
github.com/operator-framework/operator-sdk v0.12.1-0.20191114194531-79e6369540c6
github.com/spf13/pflag v1.0.3
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/client-go v11.0.0+incompatible
sigs.k8s.io/controller-runtime v0.3.0
)

// Pinned to kubernetes-1.15.4
replace (
k8s.io/api => k8s.io/api v0.0.0-20190918195907-bd6ac527cfd2
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190918201827-3de75813f604
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20190918200908-1e17798da8c1
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190918202139-0b14c719ca62
k8s.io/client-go => k8s.io/client-go v0.0.0-20190918200256-06eb1244587a
k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20190918203125-ae665f80358a
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20190918202959-c340507a5d48
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190612205613-18da4a14b22b
k8s.io/component-base => k8s.io/component-base v0.0.0-20190918200425-ed2f0867c778
k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190817025403-3ae76f584e79
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20190918203248-97c07dcbb623
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20190918201136-c3a845f1fbb2
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20190918202837-c54ce30c680e
k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20190918202429-08c8357f8e2d
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20190918202713-c34a54b3ec8e
k8s.io/kubelet => k8s.io/kubelet v0.0.0-20190918202550-958285cf3eef
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20190918203421-225f0541b3ea
k8s.io/metrics => k8s.io/metrics v0.0.0-20190918202012-3c1ca76f5bda
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20190918201353-5cc279503896
)

replace github.com/operator-framework/operator-sdk => ../../
Loading