Skip to content

Commit

Permalink
Fix kurlkinds build and add to ci (#1465)
Browse files Browse the repository at this point in the history
* Fix kurlkinds build and add to ci

* fix

* fix
  • Loading branch information
emosbaugh committed Apr 14, 2021
1 parent d2e5684 commit 8d62119
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 81 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,38 @@ jobs:

- run: make -C kurl_util deps test build


build-web:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2.1.5
with:
node-version: '12'

- run: make -C web test


build-kurlkinds:
runs-on: ubuntu-18.04
steps:
- uses: actions/setup-go@v2.1.3
with:
go-version: 1.16.0

- name: setup env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash

- uses: actions/checkout@v2

- run: |
make -C kurlkinds deps test manager
build-bin-kurl:
runs-on: ubuntu-18.04
steps:
Expand Down
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ require (
github.com/denisbrodbeck/machineid v1.0.1
github.com/fatih/color v1.10.0
github.com/foomo/htpasswd v0.0.0-20200116085101-e3a90e78da9c
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.5.0
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/itchyny/gojq v0.12.2
github.com/mattn/go-isatty v0.0.12
Expand All @@ -26,19 +27,19 @@ require (
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/vishvananda/netlink v1.1.0
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449 // indirect
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7
golang.org/x/tools v0.1.0 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 // indirect
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.20.4
k8s.io/apiextensions-apiserver v0.20.4 // indirect
k8s.io/apimachinery v0.20.4
k8s.io/client-go v0.20.4
k8s.io/klog/v2 v2.8.0 // indirect
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 // indirect
k8s.io/utils v0.0.0-20210305010621-2afb4311ab10 // indirect
sigs.k8s.io/controller-runtime v0.8.3
sigs.k8s.io/structured-merge-diff/v4 v4.1.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.1 // indirect
)
62 changes: 32 additions & 30 deletions go.sum

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions kurlkinds/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

export GO111MODULE=on

export PATH := /usr/local/kubebuilder/bin:${PATH}

# Image URL to use all building/pushing image targets
IMG ?= controller:latest

Expand All @@ -27,7 +29,7 @@ vet:
go vet ./pkg/... ./cmd/...

# Get binaries
deps: update-controller-gen update-client-gen
deps: update-controller-gen update-client-gen update-kubebuilder

# Generate code
generate: controller-gen client-gen manifests
Expand Down Expand Up @@ -60,4 +62,14 @@ update-controller-gen:

# get/update client-gen
update-client-gen:
go get k8s.io/code-generator/cmd/client-gen@v0.21.0
go get k8s.io/code-generator/cmd/client-gen@v0.20.4

update-kubebuilder: os = $(shell go env GOOS)
update-kubebuilder: arch = $(shell go env GOARCH)
update-kubebuilder: KUBEBUILDER_VERSION = 2.3.1
update-kubebuilder:
# download kubebuilder and extract it to tmp
curl -fsSL https://go.kubebuilder.io/dl/${KUBEBUILDER_VERSION}/${os}/${arch} | tar -xz -C /tmp/

sudo rm -rf /usr/local/kubebuilder
sudo mv /tmp/kubebuilder_${KUBEBUILDER_VERSION}_${os}_${arch} /usr/local/kubebuilder
9 changes: 9 additions & 0 deletions kurlkinds/config/crds/v1beta1/cluster.kurl.sh_installers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ spec:
required:
- version
type: object
ufwConfig:
properties:
bypassUFWWarning:
type: boolean
disableUFW:
type: boolean
hardFailOnUFW:
type: boolean
type: object
velero:
properties:
disableCLI:
Expand Down
2 changes: 1 addition & 1 deletion kurlkinds/pkg/apis/cluster/v1beta1/v1beta1_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var c client.Client

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds", "v1beta1")},
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
Expand Down
10 changes: 5 additions & 5 deletions kurlkinds/pkg/controller/installer/installer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ type ReconcileInstaller struct {
// +kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=cluster.kurl.sh,resources=installers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=cluster.kurl.sh,resources=installers/status,verbs=get;update;patch
func (r *ReconcileInstaller) Reconcile(request reconcile.Request) (reconcile.Result, error) {
func (r *ReconcileInstaller) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
// Fetch the Installer instance
instance := &clusterv1beta1.Installer{}
err := r.Get(context.TODO(), request.NamespacedName, instance)
err := r.Get(ctx, request.NamespacedName, instance)
if err != nil {
if errors.IsNotFound(err) {
// Object not found, return. Created objects are automatically garbage collected.
Expand Down Expand Up @@ -144,10 +144,10 @@ func (r *ReconcileInstaller) Reconcile(request reconcile.Request) (reconcile.Res
// TODO(user): Change this for the object type created by your controller
// Check if the Deployment already exists
found := &appsv1.Deployment{}
err = r.Get(context.TODO(), types.NamespacedName{Name: deploy.Name, Namespace: deploy.Namespace}, found)
err = r.Get(ctx, types.NamespacedName{Name: deploy.Name, Namespace: deploy.Namespace}, found)
if err != nil && errors.IsNotFound(err) {
log.Info("Creating Deployment", "namespace", deploy.Namespace, "name", deploy.Name)
err = r.Create(context.TODO(), deploy)
err = r.Create(ctx, deploy)
return reconcile.Result{}, err
} else if err != nil {
return reconcile.Result{}, err
Expand All @@ -158,7 +158,7 @@ func (r *ReconcileInstaller) Reconcile(request reconcile.Request) (reconcile.Res
if !reflect.DeepEqual(deploy.Spec, found.Spec) {
found.Spec = deploy.Spec
log.Info("Updating Deployment", "namespace", deploy.Namespace, "name", deploy.Name)
err = r.Update(context.TODO(), found)
err = r.Update(ctx, found)
if err != nil {
return reconcile.Result{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package installer

import (
"context"
stdlog "log"
"os"
"path/filepath"
Expand All @@ -36,7 +37,7 @@ var cfg *rest.Config

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds", "v1beta1")},
}
apis.AddToScheme(scheme.Scheme)

Expand All @@ -54,22 +55,21 @@ func TestMain(m *testing.M) {
// writes the request to requests after Reconcile is finished.
func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) {
requests := make(chan reconcile.Request)
fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) {
result, err := inner.Reconcile(req)
fn := reconcile.Func(func(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
result, err := inner.Reconcile(ctx, req)
requests <- req
return result, err
})
return fn, requests
}

// StartTestManager adds recFn
func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) {
stop := make(chan struct{})
func StartTestManager(ctx context.Context, mgr manager.Manager, g *gomega.GomegaWithT) *sync.WaitGroup {
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred())
g.Expect(mgr.Start(ctx)).NotTo(gomega.HaveOccurred())
}()
return stop, wg
return wg
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ func TestReconcile(t *testing.T) {
recFn, requests := SetupTestReconcile(newReconciler(mgr))
g.Expect(add(mgr, recFn)).NotTo(gomega.HaveOccurred())

stopMgr, mgrStopped := StartTestManager(mgr, g)
ctx, cancel := context.WithCancel(context.Background())
mgrStopped := StartTestManager(ctx, mgr, g)

defer func() {
close(stopMgr)
cancel()
mgrStopped.Wait()
}()

Expand Down

0 comments on commit 8d62119

Please sign in to comment.