Skip to content

Commit

Permalink
CircleCI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pepov committed Jun 5, 2019
1 parent 237aca9 commit a170467
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 25 deletions.
170 changes: 170 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
version: 2

integration-test-environment: &integration-test-environment
GO_VERSION: "1.12.5"
KUBECONFIG: /home/circleci/.kube/config
MINIKUBE_VERSION: v1.1.0
MINIKUBE_WANTUPDATENOTIFICATION: false
MINIKUBE_WANTREPORTERRORPROMPT: false
MINIKUBE_HOME: /home/circleci
CHANGE_MINIKUBE_NONE_USER: true
GOPATH: /go
DOCKER_LATEST: 1
GIN_MODE: release

integration-test-base: &integration-test-base
machine:
image: ubuntu-1604:201903-01
docker_layer_caching: true
steps:
- run:
name: Setup minikube
command: |
curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/${MINIKUBE_VERSION}/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- run:
name: Start minikube
background: true
command: |
sudo -E minikube start --vm-driver=none --cpus 2 --memory 4096 --kubernetes-version=${K8S_VERSION}
- run:
name: Setup kubectl
command: |
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
mkdir -p ${HOME}/.kube
touch ${HOME}/.kube/config
- checkout

- run:
name: Create go directory
command: |
sudo mkdir /go
sudo chmod 777 /go
- restore_cache:
name: Restore Go module cache
keys:
- gomod-v2-{{ .Branch }}-{{ checksum "go.sum" }}
- gomod-v2-{{ .Branch }}
- gomod-v2-master
- gomod-v2

- run:
name: Setup golang
command: |
sudo rm -rf /usr/local/go
curl -Lo go.linux-amd64.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && sudo tar -C /usr/local -xzf go.linux-amd64.tar.gz && rm go.linux-amd64.tar.gz
- run:
name: Wait for minikube
command: |
timeout 180s bash <<EOT
set -o pipefail
function is_ready()
{
kubectl get nodes -o json \
| jq '.items[].status.conditions[] | select(.type=="Ready" and .status=="True")'
}
until is_ready
do
sleep 1
done
EOT
- run:
name: Integration test
command:
make test-integration


jobs:
check:
docker:
- image: circleci/golang:1.12
environment:
GOFLAG: -mod=readonly

resource_class: small

steps:
- checkout

- restore_cache:
name: Restore Go module cache
keys:
- gomod-v2-{{ .Branch }}-{{ checksum "go.sum" }}
- gomod-v2-{{ .Branch }}
- gomod-v2-master
- gomod-v2

- run:
name: Install dependencies
command: go mod download

- save_cache:
name: Save Go module cache
key: gomod-v2-{{ .Branch }}-{{ checksum "go.sum" }}
paths:
- /go/pkg/mod
#
# - restore_cache:
# name: Restore license cache
# keys:
# - licensei-v2-{{ .Branch }}-{{ checksum "go.sum" }}
# - licensei-v2-{{ .Branch }}
# - licensei-v2-master
# - licensei-v2
#
# - run:
# name: Download license information for dependencies
# command: make license-cache
#
# - save_cache:
# name: Save license cache
# key: licensei-v2-{{ .Branch }}-{{ checksum "go.sum" }}
# paths:
# - .licensei.cache
#
# - run:
# name: Check dependency licenses
# command: make license-check

- run:
name: Run verification
command: make

integration-test-k8s1-14:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.14.2

integration-test-k8s1-13:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.13.6

integration-test-k8s1-12:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.12.9

workflows:
version: 2
ci:
jobs:
- check
- integration-test-k8s1-14:
requires:
- check
- integration-test-k8s1-13:
requires:
- check
- integration-test-k8s1-12:
requires:
- check
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,*.yaml}]
indent_size = 2

[*.go]
indent_style = tab

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

all: license fmt vet

.PHONY: license
license:
./scripts/check-header.sh

Expand All @@ -11,3 +12,6 @@ fmt:
# Run go vet against code
vet:
go vet ./...

test-integration:
go test -integration ./...
29 changes: 22 additions & 7 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2019 Banzai Cloud.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package objectmatch

import (
Expand All @@ -15,14 +30,13 @@ import (
)

var (
integration = flag.Bool("integration", false, "run integration tests")
kubeconfig = flag.String("kubeconfig", filepath.Join(homedir.HomeDir(), ".kube/config"), "kubernetes config to use for tests")
kubecontext = flag.String("kubecontext", "", "kubernetes context to use in tests")
integration = flag.Bool("integration", false, "run integration tests")
kubeconfig = flag.String("kubeconfig", filepath.Join(homedir.HomeDir(), ".kube/config"), "kubernetes config to use for tests")
kubecontext = flag.String("kubecontext", "", "kubernetes context to use in tests")
keepnamespace = flag.Bool("keepnamespace", false, "keep the kubernetes namespace that was used for the tests")
testContext = &IntegrationTestContext{}
testContext = &IntegrationTestContext{}
)


func TestMain(m *testing.M) {

klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
Expand All @@ -35,7 +49,7 @@ func TestMain(m *testing.M) {

config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: *kubeconfig},
&clientcmd.ConfigOverrides{CurrentContext:*kubecontext},
&clientcmd.ConfigOverrides{CurrentContext: *kubecontext},
).ClientConfig()
if err != nil {
panic(err.Error())
Expand All @@ -62,9 +76,10 @@ func TestMain(m *testing.M) {
}

type IntegrationTestContext struct {
Client kubernetes.Interface
Client kubernetes.Interface
Namespace string
}

func (ctx *IntegrationTestContext) CreateNamespace() error {
ns := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (m podMatcher) Match(oldOrig, newOrig *corev1.Pod) (bool, error) {
generatedTokenName := ""
tmpVolume := []corev1.Volume{}
for _, volume := range old.Spec.Volumes {
if !strings.HasPrefix(volume.Name, old.Spec.ServiceAccountName + "-token-") {
if !strings.HasPrefix(volume.Name, old.Spec.ServiceAccountName+"-token-") {
tmpVolume = append(tmpVolume, volume)
} else {
generatedTokenName = volume.Name
Expand Down
29 changes: 22 additions & 7 deletions pod_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2019 Banzai Cloud.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package objectmatch

import (
Expand All @@ -14,30 +29,30 @@ func TestIntegration_Pod(t *testing.T) {
t.Skip()
}

tests := []struct{
tests := []struct {
pod *v1.Pod
}{
{
pod: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Name: "test-pod",
Namespace: testContext.Namespace,
},
Spec: v1.PodSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "test-container", Image:"test-image",
Name: "test-container", Image: "test-image",
VolumeMounts: []v1.VolumeMount{
{
Name: "test-volume",
MountPath: "/tmp/test",
Name: "test-volume",
MountPath: "/tmp/test",
},
},
},
},
Volumes: []v1.Volume{
{
Name: "test-volume",
Name: "test-volume",
VolumeSource: v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: "/tmp/test"}},
},
},
Expand Down
7 changes: 3 additions & 4 deletions pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
package objectmatch

import (
"encoding/json"
"encoding/json"

"github.com/goph/emperror"
corev1 "k8s.io/api/core/v1"
"github.com/goph/emperror"
corev1 "k8s.io/api/core/v1"
)

type pvcMatcher struct {
Expand Down Expand Up @@ -70,4 +70,3 @@ func (m pvcMatcher) Match(old, new *corev1.PersistentVolumeClaim) (bool, error)

return matched, nil
}

Loading

0 comments on commit a170467

Please sign in to comment.