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

Docker fix #60

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2

defaults: &defaults
machine: true
working_directory: ~/go/src/github.com/nearmap/kcd
working_directory: ~/go/src/github.com/wish/kcd

deploy-env: &deploy-env
name: Tag current image as deploy candidate
Expand Down Expand Up @@ -39,8 +39,8 @@ jobs:
- run:
name: Go Report Card
command: |
curl -X POST -F 'repo=github.com/nearmap/kcd' https://goreportcard.au-api.nearmap.com/checks
echo "Report is avaialble @ https://goreportcard.au-api.nearmap.com/report/github.com/nearmap/kcd"
curl -X POST -F 'repo=github.com/wish/kcd' https://goreportcard.au-api.nearmap.com/checks
echo "Report is avaialble @ https://goreportcard.au-api.nearmap.com/report/github.com/wish/kcd"
- deploy:
name: Push application docker image
command: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.notes.mdown
.t2d
vendor/
kcd
.idea/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ We welcome all contributions and feedbacks.

# Contributors

We thank all of our [contributors](https://github.com/nearmap/kcd/graphs/contributors)!
We thank all of our [contributors](https://github.com/wish/kcd/graphs/contributors)!

**For the detailed history of contributions**

Expand Down
22 changes: 12 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
FROM golang:alpine
FROM golang:alpine AS builder

ADD . /go/src/github.com/nearmap/kcd
RUN go install github.com/nearmap/kcd
RUN apk update && apk add --no-cache git && apk add --update git mercurial && rm -rf /var/cache/apk/*
COPY . /go/src/github.com/wish/kcd
WORKDIR /go/src/github.com/wish/kcd

RUN rm -r /go/src/github.com/nearmap/kcd
RUN export GO111MODULE=on && GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/kcd

VOLUME /go/src
#Actual Image
FROM alpine:3.13.0

# TODO: this is dodgy it expects k8s files to always be available from runtime directory
VOLUME /go/src

# need to package the yaml version file using tool chains properly
RUN mkdir -p /kcd
ADD ./k8s /kcd/k8s/
ADD version /kcd/

WORKDIR /kcd
COPY --from=builder /go/bin/kcd /usr/local/bin
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

EXPOSE 2019

WORKDIR /kcd
EXPOSE 2019
USER 1001

ENTRYPOINT ["kcd"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# KCD

[![CircleCI](https://circleci.com/gh/nearmap/kcd.svg?style=svg&circle-token=e635659d5d8190eb041cc92149262a5b75470fcd)](https://circleci.com/gh/nearmap/kcd)
[![Go Report Card](https://goreportcard.com/badge/github.com/nearmap/kcd)](https://goreportcard.com/report/github.com/nearmap/kcd)
[![GoDoc](https://godoc.org/github.com/nearmap/kcd?status.svg "GoDoc")](https://godoc.org/github.com/nearmap/kcd)
[![Go Report Card](https://goreportcard.com/badge/github.com/wish/kcd)](https://goreportcard.com/report/github.com/wish/kcd)
[![GoDoc](https://godoc.org/github.com/wish/kcd?status.svg "GoDoc")](https://godoc.org/github.com/wish/kcd)
![Docker Pulls](https://img.shields.io/docker/pulls/nearmap/kcd.svg)
![GitHub (pre-)release](https://img.shields.io/github/release/nearmap/kcd/all.svg)

Expand All @@ -16,7 +16,7 @@ Kubernetes Continous Delivery (kcd), formally known as _Container_ _Version_ _Ma

Deployments that requires CI/CD, can declare [KCD](k8s/crd.yaml) resource. [kcd](k8s/kcd.yaml), KCD (Kubernetes Continous Delivery) controller starts monitoring for any new changes that should be rolled-out. If so, using the rollout strategy specified in this deployment, the rollout of new version is carried out.

kcd assumes ECR as the container registry. Supporting other registeries is T2D ([see](https://github.com/nearmap/kcd/issues/15)).
kcd assumes ECR as the container registry. Supporting other registeries is T2D ([see](https://github.com/wish/kcd/issues/15)).

The tool has 3 main parts:
- KCD Controller
Expand Down
4 changes: 2 additions & 2 deletions codegen/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ echo $CODEGEN_PKG


# ${CODEGEN_PKG}/generate-internal-groups.sh all \
# github.com/nearmap/kcd/gok8s/client github.com/nearmap/kcd/gok8s/apis github.com/nearmap/kcd/gok8s/apis \
# github.com/wish/kcd/gok8s/client github.com/wish/kcd/gok8s/apis github.com/wish/kcd/gok8s/apis \
# custom:v1 \
# --output-base "$(dirname ${BASH_SOURCE})/../../../.."

Expand All @@ -39,7 +39,7 @@ echo $CODEGEN_PKG
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh all \
github.com/nearmap/kcd/gok8s/client github.com/nearmap/kcd/gok8s/apis \
github.com/wish/kcd/gok8s/client github.com/wish/kcd/gok8s/apis \
custom:v1 \
--output-base "$(dirname ${BASH_SOURCE})/../../../.."
# To use your own boilerplate text append:
Expand Down
4 changes: 2 additions & 2 deletions config/options.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package config

import (
"github.com/nearmap/kcd/events"
"github.com/nearmap/kcd/stats"
"github.com/wish/kcd/events"
"github.com/wish/kcd/stats"
)

// Options contains additional (optional) configuration for the controller
Expand Down
10 changes: 5 additions & 5 deletions deploy/bluegreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"time"

"github.com/golang/glog"
kcd1 "github.com/nearmap/kcd/gok8s/apis/custom/v1"
"github.com/nearmap/kcd/gok8s/workload"
"github.com/nearmap/kcd/registry"
"github.com/nearmap/kcd/state"
"github.com/nearmap/kcd/verify"
kcd1 "github.com/wish/kcd/gok8s/apis/custom/v1"
"github.com/wish/kcd/gok8s/workload"
"github.com/wish/kcd/registry"
"github.com/wish/kcd/state"
"github.com/wish/kcd/verify"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
10 changes: 5 additions & 5 deletions deploy/bluegreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package deploy_test
import (
"testing"

"github.com/nearmap/kcd/deploy"
"github.com/nearmap/kcd/deploy/fake"
kcd1 "github.com/nearmap/kcd/gok8s/apis/custom/v1"
"github.com/nearmap/kcd/gok8s/workload"
"github.com/nearmap/kcd/registry"
"github.com/wish/kcd/deploy"
"github.com/wish/kcd/deploy/fake"
kcd1 "github.com/wish/kcd/gok8s/apis/custom/v1"
"github.com/wish/kcd/gok8s/workload"
"github.com/wish/kcd/registry"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gofake "k8s.io/client-go/kubernetes/fake"
Expand Down
59 changes: 40 additions & 19 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package deploy

import (
"github.com/golang/glog"
kcd1 "github.com/nearmap/kcd/gok8s/apis/custom/v1"
"github.com/nearmap/kcd/gok8s/workload"
k8s "github.com/nearmap/kcd/gok8s/workload"
"github.com/nearmap/kcd/registry"
"github.com/nearmap/kcd/state"
kcd1 "github.com/wish/kcd/gok8s/apis/custom/v1"
"github.com/wish/kcd/gok8s/workload"
k8s "github.com/wish/kcd/gok8s/workload"
"github.com/wish/kcd/registry"
"github.com/wish/kcd/state"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -82,24 +82,24 @@ func CheckPods(cs kubernetes.Interface, namespace string, target RolloutTarget,
if err != nil {
return false, errors.Wrapf(err, "failed to get pods for target %s", target.Name())
}

if len(pods) == 0 {
glog.V(4).Infof("%s has %d replicaset, thus deployment succeeded", target.Name(), len(pods))
return true, nil
}

if len(pods) < int(num) {
glog.V(2).Infof("insufficient pods found for target %s: found %d but need %d", target.Name(), len(pods), num)
return false, nil
}

// firstly, check if there are old pods left
for _, pod := range pods {
if pod.Status.Phase != corev1.PodRunning {
glog.V(2).Infof("Still waiting for rollout: pod %s phase is %v", pod.Name, pod.Status.Phase)
return false, nil
}

for _, cs := range pod.Status.ContainerStatuses {
if !cs.Ready {
glog.V(2).Infof("Still waiting for rollout: pod=%s, container=%s is not ready", pod.Name, cs.Name)
return false, nil
}
}

//if pod.Status.Phase != corev1.PodRunning {
// glog.V(2).Infof("Still waiting for rollout: pod %s phase is %v", pod.Name, pod.Status.Phase)
// return false, nil
//}
glog.V(4).Infof("Check pod spev version %v, $v", pod.Name, pod.Namespace)
ok, err := workload.CheckPodSpecVersion(pod.Spec, kcd, version)
if err != nil {
return false, errors.Wrapf(err, "failed to check container version for target %s", target.Name())
Expand All @@ -110,7 +110,28 @@ func CheckPods(cs kubernetes.Interface, namespace string, target RolloutTarget,
}
}

glog.V(2).Info("All pods and containers are ready")
// secondly, check if new pods are up and running
for _, pod := range pods {
if CheckPodRunningState(pod) {
glog.V(4).Infof("Pod %s in latest version is ready", pod.Name)
return true, nil
}
}

//glog.V(2).Info("All pods and containers are ready")
glog.V(2).Info("Still waiting for rollout, new pods are not ready yet")
return false, nil
}

return true, nil
// CheckPodRunningState checks whether a pod is running and all of its container is in ready state.
func CheckPodRunningState(pod corev1.Pod) bool {
if pod.Status.Phase != corev1.PodRunning {
return false
}
for _, cs := range pod.Status.ContainerStatuses {
if !cs.Ready {
return false
}
}
return true
}
4 changes: 2 additions & 2 deletions deploy/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"reflect"
"time"

"github.com/nearmap/kcd/deploy"
kcd1 "github.com/nearmap/kcd/gok8s/apis/custom/v1"
"github.com/wish/kcd/deploy"
kcd1 "github.com/wish/kcd/gok8s/apis/custom/v1"
corev1 "k8s.io/api/core/v1"
)

Expand Down
12 changes: 6 additions & 6 deletions deploy/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"time"

"github.com/golang/glog"
kcd1 "github.com/nearmap/kcd/gok8s/apis/custom/v1"
"github.com/nearmap/kcd/gok8s/workload"
"github.com/nearmap/kcd/registry"
"github.com/nearmap/kcd/state"
"github.com/nearmap/kcd/verify"
kcd1 "github.com/wish/kcd/gok8s/apis/custom/v1"
"github.com/wish/kcd/gok8s/workload"
"github.com/wish/kcd/registry"
"github.com/wish/kcd/state"
"github.com/wish/kcd/verify"
"github.com/pkg/errors"
"k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -147,7 +147,7 @@ func (sd *SimpleDeployer) checkRollout(target RolloutTarget) (complete bool, err
return false, state.NewFailed("rollout failed for target=%s, version=%s", target.Name(), sd.version)
}

success, err := CheckPods(sd.cs, sd.namespace, target, 1, sd.kcd, sd.version)
success, err := CheckPods(sd.cs, sd.namespace, target, 0, sd.kcd, sd.version)
if err != nil {
return false, errors.Wrapf(err, "failed to check pods during rollout for %s", target.Name())
}
Expand Down
10 changes: 5 additions & 5 deletions deploy/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"reflect"
"testing"

"github.com/nearmap/kcd/deploy"
"github.com/nearmap/kcd/deploy/fake"
kcd1 "github.com/nearmap/kcd/gok8s/apis/custom/v1"
"github.com/nearmap/kcd/gok8s/workload"
"github.com/nearmap/kcd/registry"
"github.com/wish/kcd/deploy"
"github.com/wish/kcd/deploy/fake"
kcd1 "github.com/wish/kcd/gok8s/apis/custom/v1"
"github.com/wish/kcd/gok8s/workload"
"github.com/wish/kcd/registry"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apimacherrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
k8s:
build:
context: .
working_dir: /go/src/github.com/nearmap/kcd
working_dir: /go/src/github.com/wish/kcd
entrypoint: env CGO_ENABLED=0 GOCACHE=/tmp go test ./...
volumes:
- .:/go/src/github.com/nearmap/kcd
- .:/go/src/github.com/wish/kcd
26 changes: 26 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module github.com/wish/kcd

go 1.12

require (
github.com/DataDog/datadog-go v4.4.0+incompatible
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/aws/aws-sdk-go v1.37.14
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/heroku/docker-registry-client v0.0.0-20190909225348-afc9e1acc3d5
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/twinj/uuid v1.0.0
goji.io v2.0.2+incompatible
k8s.io/api v0.20.4
k8s.io/apiextensions-apiserver v0.20.4
k8s.io/apimachinery v0.20.4
k8s.io/apiserver v0.20.4
k8s.io/client-go v11.0.0+incompatible
k8s.io/klog v1.0.0 // indirect
)

replace (
bitbucket.org/ww/goautoneg => github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d
)
Loading