Skip to content
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

Migrate to go modules #190

Merged
merged 4 commits into from
Mar 17, 2020
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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bin/
pkg/crd/apis/danm/*/zz_generated.deepcopy.go
pkg/crd/client/
pkg/vendor/
vendor/
.idea/
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ env:

language: go

go: 1.13.5

go:
- 1.13.x

services: docker

install:
Expand Down
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ So, you are adamant you want to contribute to our project, and maybe even alread

Keep in mind that the project is:

- written in Golang, so you will need a properly set-up Golang 1.9+ development environment
- managed by Glide, so you will need to install it on your machine (for the time being)
- written in Golang and using `go module` feature for dependency management, so you will need a properly set-up `Golang 1.12+` development environment
- build scripts depend on `docker`, to be able to run scripts locally you will have to install it on your machine

Once you have the prerequisites, fork our project, code your changes, test your contribution, then start a normal GitHub review process.

Expand All @@ -61,8 +61,6 @@ However, we require you to break-up big contributions into smaller, functionally
### Future plans
The following topics are on our mind right now, so if you are looking for topic to start with these are as good as any!

We are aiming to adopt the go module style dependency management within our project.

Being a new project, we have not yet integrated the repository to an automated CI system (like Travis).

Increasing UT coverage of existing code is alway appreciated.
Expand Down
4 changes: 2 additions & 2 deletions build_docker.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh -e

echo 'Updating alpine base image'
docker pull alpine:latest
docker pull golang:1.13-alpine3.10

echo 'Building DANM builder container'
docker build --no-cache --tag=danm_builder:1.0 scm/build

echo 'Running DANM build'
docker run --rm --net=host --name=danm_build -v $GOPATH/bin:/usr/local/go/bin -v $GOPATH/src:/usr/local/go/src danm_builder:1.0
docker run --rm --net=host --name=danm_build -v ${GOPATH}/bin:/go/bin -v ${GOPATH}/src:/go/src -v ${GOPATH}/pkg:/go/pkg danm_builder:1.0

echo 'Cleaning up DANM builder container'
docker rmi -f danm_builder:1.0
Expand Down
22 changes: 17 additions & 5 deletions cmd/svcwatcher/svcwatcher.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"context"
"flag"
"k8s.io/client-go/transport"
"log"
"time"
"os"
Expand Down Expand Up @@ -38,8 +40,17 @@ func main() {
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
glog.Fatalf("Error building kubeconfig: %s", err.Error())
return
}

// use a Go context so we can tell the leaderelection code when we
// want to step down
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// use a client that will stop allowing new requests once the context ends
cfg.Wrap(transport.ContextCanceller(ctx, fmt.Errorf("the leader is shutting down")))

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
Expand All @@ -59,11 +70,11 @@ func main() {
kubeInformerFactory.Core().V1().Endpoints(),
danmInformerFactory.Danm().V1().DanmEps())

run := func(stopCh <-chan struct{}) {
go kubeInformerFactory.Start(stopCh)
go danmInformerFactory.Start(stopCh)
run := func(ctx context.Context) {
go kubeInformerFactory.Start(ctx.Done())
go danmInformerFactory.Start(ctx.Done())

if err = controller.Run(10, stopCh); err != nil {
if err = controller.Run(10, ctx.Done()); err != nil {
glog.Fatalf("Error running controller: %s", err.Error())
}
}
Expand All @@ -72,6 +83,7 @@ func main() {
"kube-system",
"danm-svc-controller",
kubeClient.CoreV1(),
kubeClient.CoordinationV1(),
resourcelock.ResourceLockConfig{
Identity: GetHostname(),
EventRecorder: createRecorder(kubeClient, "danm-svc-controller"),
Expand All @@ -80,7 +92,7 @@ func main() {
glog.Fatalf("Error creating lock: %v", err)
}

leaderelection.RunOrDie(leaderelection.LeaderElectionConfig{
leaderelection.RunOrDie(ctx, leaderelection.LeaderElectionConfig{
Lock: rl,
LeaseDuration: 10 * time.Second,
RenewDeadline: 5 * time.Second,
Expand Down
1 change: 1 addition & 0 deletions crd/apis/danm/v1/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate bash -c "cg(){ go list -m -f {{.Dir}} k8s.io/code-generator;}; crd(){ cat<<<'github.com/nokia/danm/crd';}; GOFLAGS='' bash $(cg)/generate-groups.sh all $(crd)/client $(crd)/apis danm:v1 --go-header-file $(cg)/hack/boilerplate.go.txt"
// +k8s:deepcopy-gen=package

// Package v1 is the v1 version of the API.
Expand Down
10 changes: 5 additions & 5 deletions crd/apis/danm/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions crd/client/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions crd/client/clientset/versioned/fake/clientset_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crd/client/clientset/versioned/typed/danm/v1/danm_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deployment-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ go get -d github.com/nokia/danm
cd $GOPATH/src/github.com/nokia/danm
./build_danm.sh
```
This will first build the Alpine based builder container, mount the $GOPATH/src and the $GOPATH/bin directory into it, and invoke the necessary script to build all binaries inside the container.
This will first build the Alpine based builder container, mount the $GOPATH/src, $GOPATH/bin and $GOPATH/pkg directory into it, and invoke the necessary script to build all binaries inside the container.
The builder container destroys itself once its purpose has been fulfilled.

The result will be 6, statically linked binaries put into your $GOPATH/bin directory.
Expand Down
Loading