Skip to content

Commit

Permalink
[Cherry Pick for 1.10.x] (#302)
Browse files Browse the repository at this point in the history
* (enhancement)resources: add argo rollouts as a supported parent resource for chaos (#300)

* (enhancement)resources: add argo rollouts as a supported parent resource for chaos

Signed-off-by: ksatchit <[email protected]>

* (fix)resources: add namespace and label selector for app filter in case of dynamic client use

Signed-off-by: ksatchit <[email protected]>

* (lint)resources: add right comment as per lint req

Signed-off-by: ksatchit <[email protected]>

* chore(add): Add multiarch image into master chaos-operator (#301)

Signed-off-by: Udit Gaurav <[email protected]>

Co-authored-by: Udit Gaurav <[email protected]>
  • Loading branch information
Karthik Satchitanand and uditgaurav authored Nov 15, 2020
1 parent 520679f commit 6c4e3dc
Show file tree
Hide file tree
Showing 17 changed files with 518 additions and 121 deletions.
96 changes: 68 additions & 28 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:

build:
machine:
image: circleci/classic:201808-01
image: ubuntu-1604:202007-01
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
environment:
K8S_VERSION: v1.12.0
Expand All @@ -20,10 +20,25 @@ jobs:
IMGTAG: ci
steps:
- checkout

- run:
name: Setup buildx
command: |
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L --output ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64
chmod a+x ~/.docker/cli-plugins/docker-buildx
docker buildx version
export DOCKER_CLI_EXPERIMENTAL=enabled
sudo apt-get update && sudo apt-get install qemu-user-static -y
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes i
docker buildx create --name multibuilder
docker buildx inspect multibuilder --bootstrap
docker buildx use multibuilder
- 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/
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/
- run:
name: Setup minikube
command: |
Expand All @@ -46,33 +61,42 @@ jobs:
source $BASH_ENV
- run: make deps
- run: make gotasks
- run: |
docker build . -f build/Dockerfile -t ${REPONAME}/${IMGNAME}:${IMGTAG}
- run: |
docker buildx build --file build/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag ${REPONAME}/${IMGNAME}:${IMGTAG} .
- run: make test
- run: |
docker save -o workspace/image.tar ${REPONAME}/${IMGNAME}:${IMGTAG}
- run: bash <(curl -s https://codecov.io/bash) -vz
- persist_to_workspace:
root: workspace
paths:
- image.tar
- env-vars

push:
machine:
image: circleci/classic:201808-01
image: ubuntu-1604:202007-01
environment:
IMGTAG: ci
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
steps:
- attach_workspace:
at: /tmp/workspace
- run: |
cat /tmp/workspace/env-vars >> $BASH_ENV
- checkout
- run: |
docker load -i /tmp/workspace/image.tar
~/go/src/github.com/litmuschaos/chaos-operator/buildscripts/push --type=ci

- run:
name: Setup buildx
command: |
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L --output ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64
chmod a+x ~/.docker/cli-plugins/docker-buildx
docker buildx version
export DOCKER_CLI_EXPERIMENTAL=enabled
sudo apt-get update && sudo apt-get install qemu-user-static -y
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes i
docker buildx create --name multibuilder
docker buildx inspect multibuilder --bootstrap
docker buildx use multibuilder
- run: make build
- run:
name: push
command: ~/go/src/github.com/litmuschaos/chaos-operator/buildscripts/push --type=ci
environment:
REPONAME: litmuschaos
IMGNAME: chaos-operator
IMGTAG: ci

trivy-check:
machine: true
Expand All @@ -92,19 +116,35 @@ jobs:
release:
machine:
image: circleci/classic:201808-01
image: ubuntu-1604:202007-01
environment:
IMGTAG: ci
IMGTAG: latest
working_directory: ~/go/src/github.com/litmuschaos/chaos-operator
steps:
- attach_workspace:
at: /tmp/workspace
- run: |
cat /tmp/workspace/env-vars >> $BASH_ENV
- checkout
- run: |
docker load -i /tmp/workspace/image.tar
~/go/src/github.com/litmuschaos/chaos-operator/buildscripts/push --type=release
- run:
name: Setup buildx
command: |
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L --output ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64
chmod a+x ~/.docker/cli-plugins/docker-buildx
docker buildx version
export DOCKER_CLI_EXPERIMENTAL=enabled
sudo apt-get update && sudo apt-get install qemu-user-static -y
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes i
docker buildx create --name multibuilder
docker buildx inspect multibuilder --bootstrap
docker buildx use multibuilder
- run: make build
- run:
name: release push
command: ~/go/src/github.com/litmuschaos/chaos-operator/buildscripts/push --type=release
environment:
REPONAME: litmuschaos
IMGNAME: chaos-operator
IMGTAG: latest

workflows:
version: 2
Expand Down Expand Up @@ -137,4 +177,4 @@ workflows:
branches:
ignore: /.*/
tags:
only: /.*/
only: /.*/
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DOCKER_IMAGE ?= chaos-operator
DOCKER_TAG ?= latest

.PHONY: all
all: deps format lint build test dockerops
all: deps format lint build test dockerops dockerops-amd64

.PHONY: help
help:
Expand Down Expand Up @@ -68,7 +68,7 @@ build:
@echo "------------------"
@echo "--> Build Chaos Operator"
@echo "------------------"
@go build -o ${GOPATH}/src/github.com/litmuschaos/chaos-operator/build/_output/bin/chaos-operator -gcflags all=-trimpath=${GOPATH} -asmflags all=-trimpath=${GOPATH} github.com/litmuschaos/chaos-operator/cmd/manager
@./build/go-multiarch-build.sh github.com/litmuschaos/chaos-operator/cmd/manager

.PHONY: test
test:
Expand All @@ -82,9 +82,20 @@ dockerops:
@echo "------------------"
@echo "--> Build & Push chaos-operator docker image"
@echo "------------------"
sudo docker build . -f build/Dockerfile -t $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG)
sudo docker buildx build --file build/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) .
REPONAME=$(DOCKER_REPO) IMGNAME=$(DOCKER_IMAGE) IMGTAG=$(DOCKER_TAG) ./buildscripts/push

.PHONY: dockerops-amd64
dockerops-amd64:
@echo "--------------------------------------------"
@echo "--> Build chaos-operator amd-64 docker image"
@echo "--------------------------------------------"
sudo docker build --file build/Dockerfile --tag $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG) . --build-arg TARGETARCH=amd64
@echo "--------------------------------------------"
@echo "--> Push chaos-operator amd-64 docker image"
@echo "--------------------------------------------"
sudo docker push $(DOCKER_REPO)/$(DOCKER_IMAGE):$(DOCKER_TAG)

unused-package-check:
@echo "------------------"
@echo "--> Check unused packages for the chaos-operator"
Expand All @@ -93,3 +104,4 @@ unused-package-check:
if [ -n "$${tidy}" ]; then \
echo "go mod tidy checking failed!"; echo "$${tidy}"; echo; \
fi

6 changes: 4 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM registry.access.redhat.com/ubi7-dev-preview/ubi-minimal:7.6
FROM golang:1.14.2

ARG TARGETARCH

ENV OPERATOR=/usr/local/bin/chaos-operator \
USER_UID=1001 \
USER_NAME=chaos-operator

# install operator binary
COPY build/_output/bin/chaos-operator ${OPERATOR}
COPY build/_output/bin/chaos-operator${TARGETARCH} ${OPERATOR}

COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup
Expand Down
36 changes: 0 additions & 36 deletions build/gitlab/stages/1-cluster-setup/gcp

This file was deleted.

31 changes: 0 additions & 31 deletions build/gitlab/stages/2-cluster-cleanup/cluster-cleanup

This file was deleted.

30 changes: 30 additions & 0 deletions build/go-multiarch-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

package=$1
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name>"
exit 1
fi

package_split=(${package//\// })
package_name=${package_split[-1]}

# add the arch for which we want to build the image
platforms=("linux/amd64" "linux/arm64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=build/_output/bin/chaos-operator$GOARCH

# The script executes for the argument passed (in package variable)
# here the arg will be "github.com/litmuschaos/chaos-operator/cmd/manager" for creating binary
env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package

if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done
12 changes: 4 additions & 8 deletions buildscripts/push
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash
set -e

# Push CI images
# Push push CI images
function push_ci_image(){

echo "Pushing ${REPONAME}/${IMGNAME}:${IMGTAG} ..."
docker push ${REPONAME}/${IMGNAME}:${IMGTAG}
docker buildx build --file build/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag ${REPONAME}/${IMGNAME}:${IMGTAG} .

}

Expand All @@ -18,16 +18,12 @@ function push_release_image(){
# When github is tagged with a release, then CircleCI will
# set the release tag in env CIRCLE_TAG
echo "Pushing ${REPONAME}/${IMGNAME}:${CIRCLE_TAG} ..."
docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:${CIRCLE_TAG}
docker push ${REPONAME}/${IMGNAME}:${CIRCLE_TAG}
docker buildx build --file build/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag ${REPONAME}/${IMGNAME}:${CIRCLE_TAG} .
echo "Pushing ${REPONAME}/${IMGNAME}:latest ..."
docker tag ${IMAGEID} ${REPONAME}/${IMGNAME}:latest
docker push ${REPONAME}/${IMGNAME}:latest
docker buildx build --file build/Dockerfile --progress plane --push --platform linux/arm64,linux/amd64 --tag ${REPONAME}/${IMGNAME}:latest .
fi;

}


# Check for Image Details
if [ -z "${REPONAME}" ] || [ -z "${IMGNAME}" ] || [ -z "${IMGTAG}" ]
then
Expand Down
2 changes: 1 addition & 1 deletion deploy/chaos_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
properties:
appkind:
type: string
pattern: ^(^$|deployment|statefulset|daemonset|deploymentconfig)$
pattern: ^(^$|deployment|statefulset|daemonset|deploymentconfig|rollout)$
applabel:
type: string
pattern: (([a-z0-9A-Z_\.-/]+)=([a-z0-9A-Z_\.-/_]+)|^$)
Expand Down
2 changes: 1 addition & 1 deletion deploy/crds/chaosengine_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
properties:
appkind:
type: string
pattern: ^(^$|deployment|statefulset|daemonset|deploymentconfig)$
pattern: ^(^$|deployment|statefulset|daemonset|deploymentconfig|rollout)$
applabel:
pattern: (([a-z0-9A-Z_\.-/]+)=([a-z0-9A-Z_\.-/_]+)|^$)
type: string
Expand Down
4 changes: 2 additions & 2 deletions deploy/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ metadata:
app.kubernetes.io/managed-by: kubectl
name: litmus
rules:
- apiGroups: ["","apps","batch","apps.openshift.io"]
resources: ["jobs","deployments","replicationcontrollers","daemonsets","replicasets","statefulsets","deploymentconfigs","secrets"]
- apiGroups: ["","apps","batch","apps.openshift.io","argoproj.io"]
resources: ["jobs","deployments","replicationcontrollers","daemonsets","replicasets","statefulsets","deploymentconfigs","rollouts","secrets"]
verbs: ["get","list","watch","deletecollection"]
- apiGroups: ["","litmuschaos.io"]
resources: ["pods","configmaps","events","services","chaosengines","chaosexperiments","chaosresults"]
Expand Down
Loading

0 comments on commit 6c4e3dc

Please sign in to comment.