Skip to content

Commit

Permalink
Merge pull request #13 from alicerum/bundle-operator
Browse files Browse the repository at this point in the history
github actions workflows for bundle and operator images
  • Loading branch information
openshift-merge-robot authored Sep 1, 2021
2 parents b0f27af + 5257069 commit 4dc4648
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 34 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
name: ci/github
jobs:
checksecret:
name: Check if REGISTRY_USERNAME is set in github secrets
runs-on: ubuntu-latest
outputs:
is_registry_username_set: ${{ steps.checksecret_job.outputs.is_registry_username_set }}
steps:
- name: Check if REGISTRY_USERNAME is set
id: checksecret_job
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
run: |
echo "is_registry_username_set: ${{ env.REGISTRY_USERNAME != '' }}"
echo "::set-output name=is_registry_username_set::${{ env.REGISTRY_USERNAME != '' }}"
bundle-build:
needs: [ checksecret ]
if: needs.checksecret.outputs.is_registry_username_set == 'true'
strategy:
fail-fast: false
matrix:
go-version: [ 1.16.x ]
os: [ ubuntu-latest ]
kubernetes:
- v1.20.7
max-parallel: 2
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Check out Code
uses: actions/checkout@v2
- name: Install kubectl
uses: azure/setup-kubectl@v1
with:
version: ${{ matrix.kubernetes }}
- name: Create kind cluster
uses: helm/[email protected]
with:
version: v0.10.0
node_image: kindest/node:${{ matrix.kubernetes }}
cluster_name: kind
wait: 120s
- name: Verify kind cluster
run: |
echo "# Using KinD context..."
kubectl config use-context "kind-kind"
echo "# KinD nodes:"
kubectl get nodes
- name: Login to the docker registry
env:
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
run: echo "$REGISTRY_PASSWORD" | docker login --username "$REGISTRY_USERNAME" --password-stdin quay.io
- name: Make and push Operator image
env:
IMAGE_REPO: quay.io/shipwright
TAG: pr-${{ github.event.number }}
run: |
make ko-publish IMAGE_REPO=ko.local
docker tag ko.local/operator:${TAG} $IMAGE_REPO/operator-pr:${TAG}
docker push $IMAGE_REPO/operator-pr:${TAG}
- name: Make and push Bundle image
env:
IMAGE_REPO: quay.io/shipwright
TAG: pr-${{ github.event.number }}
BUNDLE_IMG_NAME: operator-bundle-pr
OPERATOR_IMG_NAME: operator-pr
run: |
make bundle-push
- name: Install OLM
run: ./bin/operator-sdk olm install
- name: Deploy Operator Bundle Image via subscription
env:
TAG: pr-${{ github.event.number }}
run: |
./bin/operator-sdk run bundle \
quay.io/shipwright/operator-bundle-pr:$TAG \
41 changes: 41 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release

on:
workflow_dispatch:
inputs:
release:
description: 'Desired tag'
required: true
tags:
description: 'Previous tag'
required: true

jobs:
release:
if: ${{ github.repository == 'shipwright-io/operator' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2

- name: Login to docker
env:
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
run: |
echo "$REGISTRY_PASSWORD" | docker login --username "$REGISTRY_USERNAME" --password-stdin
- name: Build and upload Operator Image
env:
VERSION: ${{ github.events.input.release }}
run: |
make ko-publish
- name: Build and upload Operator Bundle Image
env:
VERSION: ${{ github.events.input.release }}
run: |
make bundle-push
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -8,6 +7,9 @@
bin
testbin/*

# OS specific files
**/.DS_Store

# Test binary, build with `go test -c`
*.test

Expand Down
33 changes: 21 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= quay.io/shipwright/operator-bundle:$(VERSION)

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"

Expand All @@ -40,9 +36,19 @@ endif

CONTAINER_ENGINE ?= docker
IMAGE_REPO ?= quay.io/shipwright
TAG ?= latest
TAG ?= $(VERSION)
IMAGE_PUSH ?= true

BUNDLE_IMG_NAME ?= operator-bundle
OPERATOR_IMG_NAME ?= operator

# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_REPO)/$(OPERATOR_IMG_NAME):$(TAG)

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(IMAGE_REPO)/$(BUNDLE_IMG_NAME):$(TAG)

# operating-system type and architecture based on golang
OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)
Expand Down Expand Up @@ -74,7 +80,7 @@ uninstall: manifests kustomize

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller="${IMAGE_REPO}/operator:${TAG}"
cd config/manager && $(KUSTOMIZE) edit set image controller="$(IMG)"
$(KUSTOMIZE) build config/default | kubectl apply -f -

# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
Expand All @@ -85,9 +91,6 @@ undeploy:
SED_BIN ?= sed
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Fix pluralization of ShipwrightBuilds in generated manifests
# This can be removed when operator-sdk is upgraded to v1.5.x
SED_BIN=${SED_BIN} hack/fix-plurals.sh

# Verify manifests were generated and committed to git
verify-manifests: manifests
Expand Down Expand Up @@ -129,7 +132,7 @@ ko-publish: ko
# Download controller-gen locally if necessary
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen:
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1)

# Download kustomize locally if necessary
KUSTOMIZE = $(shell pwd)/bin/kustomize
Expand Down Expand Up @@ -159,15 +162,21 @@ endef
.PHONY: bundle
bundle: manifests kustomize operator-sdk
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller="${IMAGE_REPO}/operator:${TAG}"
cd config/manager && $(KUSTOMIZE) edit set image controller="${IMG}"
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle


# Verify bundle manifests were generated and committed to git
verify-bundle: bundle
hack/check-git-status.sh bundle

# Build the bundle image.
.PHONY: bundle-build
bundle-build:
bundle-build: bundle
$(CONTAINER_ENGINE) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

# Push the bundle image to the registry
.PHONY: bundle-push
bundle-push: bundle-build
$(CONTAINER_ENGINE) push $(BUNDLE_IMG)
8 changes: 6 additions & 2 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ layout: go.kubebuilder.io/v3
projectName: operator
repo: github.com/shipwright-io/operator
resources:
- crdVersion: v1
- api:
crdVersion: v1
controller: true
domain: shipwright.io
group: operator
kind: ShipwrightBuild
path: github.com/shipwright-io/operator/api/v1alpha1
version: v1alpha1
version: 3-alpha
version: "3"
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
9 changes: 7 additions & 2 deletions bundle.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
FROM scratch

# Core bundle labels.
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.4.2
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.9.0+git
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/

# Labels for testing.
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/

# Copy files to locations specified by labels.
COPY bundle/manifests /manifests/
COPY bundle/metadata /metadata/
COPY bundle/tests/scorecard /tests/scorecard/
7 changes: 4 additions & 3 deletions bundle/manifests/operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ metadata:
}
]
capabilities: Basic Install
operators.operatorframework.io/builder: operator-sdk-v1.4.2
operators.operatorframework.io/builder: operator-sdk-v1.9.0+git
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: operator.v0.0.1
namespace: placeholder
spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: ShipwrightBuild represents the deployment of Shipwright's build controller on a Kubernetes cluster.
- description: ShipwrightBuild represents the deployment of Shipwright's build
controller on a Kubernetes cluster.
displayName: Shipwright Build
kind: ShipwrightBuild
name: shipwrightbuilds.operator.shipwright.io
Expand Down Expand Up @@ -241,7 +242,7 @@ spec:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
image: quay.io/shipwright/operator:latest
image: quay.io/shipwright/operator:0.0.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
19 changes: 13 additions & 6 deletions bundle/manifests/operator.shipwright.io_shipwrightbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
controller-gen.kubebuilder.io/version: v0.6.1
creationTimestamp: null
name: shipwrightbuilds.operator.shipwright.io
spec:
Expand All @@ -17,21 +17,28 @@ spec:
- name: v1alpha1
schema:
openAPIV3Schema:
description: ShipwrightBuild represents the deployment of Shipwright's build controller on a Kubernetes cluster.
description: ShipwrightBuild represents the deployment of Shipwright's build
controller on a Kubernetes cluster.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ShipwrightBuildSpec defines the configuration of a Shipwright Build deployment.
description: ShipwrightBuildSpec defines the configuration of a Shipwright
Build deployment.
properties:
targetNamespace:
description: TargetNamespace is the target namespace where Shipwright's build controller will be deployed.
description: TargetNamespace is the target namespace where Shipwright's
build controller will be deployed.
type: string
type: object
status:
Expand Down
11 changes: 7 additions & 4 deletions bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
annotations:
operators.operatorframework.io.bundle.channels.v1: alpha
operators.operatorframework.io.bundle.manifests.v1: manifests/
# Core bundle annotations.
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
operators.operatorframework.io.bundle.manifests.v1: manifests/
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: operator
operators.operatorframework.io.metrics.builder: operator-sdk-v1.4.2
operators.operatorframework.io.bundle.channels.v1: alpha
operators.operatorframework.io.metrics.builder: operator-sdk-v1.9.0+git
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3
operators.operatorframework.io.test.config.v1: tests/scorecard/

# Annotations for testing.
operators.operatorframework.io.test.mediatype.v1: scorecard+v1
operators.operatorframework.io.test.config.v1: tests/scorecard/
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
controller-gen.kubebuilder.io/version: v0.6.1
creationTimestamp: null
name: shipwrightbuilds.operator.shipwright.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/shipwright/operator
newTag: latest
newTag: 0.0.1
3 changes: 2 additions & 1 deletion config/manifests/bases/operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: ShipwrightBuild represents the deployment of Shipwright's build controller on a Kubernetes cluster.
- description: ShipwrightBuild represents the deployment of Shipwright's build
controller on a Kubernetes cluster.
displayName: Shipwright Build
kind: ShipwrightBuild
name: shipwrightbuilds.operator.shipwright.io
Expand Down
2 changes: 1 addition & 1 deletion hack/install-operator-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
set -e

DEST="${1:-bin/operator-sdk}"
SDK_VERSION="${SDK_VERSION:-1.4.2}"
SDK_VERSION="${SDK_VERSION:-1.9.1}"

OS="${OS:-linux}"
ARCH="${ARCH:-amd64}"
Expand Down

0 comments on commit 4dc4648

Please sign in to comment.