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

BUILD-475: Build Inventory and PipelineRun Controller #4

Merged
merged 9 commits into from
Dec 2, 2022
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 3 additions & 1 deletion .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ runs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
go-version: 1.18.x
cache: true
- uses: imjasonh/[email protected]
9 changes: 2 additions & 7 deletions .github/actions/shipwright/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ description: set up shipwright build controller on a kind instance
runs:
using: composite
steps:
- uses: helm/kind-action@v1.2.0
- uses: helm/kind-action@v1.4.0
with:
version: v0.14.0
cluster_name: kind
wait: 120s
- shell: bash
run: make verify-kind
- uses: azure/setup-kubectl@v1
- uses: imjasonh/[email protected]
- shell: bash
run: make install-shipwright
- uses: shipwright-io/setup@v1
20 changes: 15 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ jobs:
- name: test-unit
run: make test-unit

test-e2e:
name: test-e2e
test-integration:
name: test-integration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: ./.github/actions/shipwright

- name: test-e2e
run: make test-e2e
- name: test-integration
run: make test-integration

# test-e2e:
# name: test-e2e
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: ./.github/actions/setup
# - uses: ./.github/actions/shipwright

# - name: test-e2e
# run: make test-e2e
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.test
triggers
/bin/
/*.out
/*.test
/triggers
2 changes: 2 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
defaultBaseImage: registry.access.redhat.com/ubi9/ubi-minimal:latest
122 changes: 99 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,131 @@
APP = triggers

# temporary directory to store auxiliary tools
LOCAL_BIN ?= $(shell pwd)/bin

# full path to the application executable
BIN ?= $(LOCAL_BIN)/$(APP)

# container image prefix, the final part and tag are appended afterwards
IMAGE_BASE ?= ghcr.io/shipwright-io
IMAGE_TAG ?= latest

GOFLAGS ?= -v -mod=vendor -race
GOFLAGS_TEST ?= -v -cover -race
# golang flags and settings
GOFLAGS ?= -v -a
GOFLAGS_TEST ?= -v -race -cover
CGO_ENABLED ?= 0

# deployment target namespace, same default than Shipwright Build project
NAMESPACE ?= shipwright-build

# ko base image repository and options
KO_DOCKER_REPO ?= $(IMAGE_BASE)
KO_OPTS ?= --base-import-paths --tags=${IMAGE_TAG}

.EXPORT_ALL_VARIABLES:
# controller-gen version and full path to the executable
CONTROLLER_TOOLS_VERSION ?= v0.10.0
CONTROLLER_GEN ?= $(LOCAL_BIN)/controller-gen

# envtest version and full path to the executable
ENVTEST_K8S_VERSION ?= 1.23
ENVTEST ?= $(LOCAL_BIN)/setup-envtest

# chart base directory and path to the "templates" folder
CHART_DIR ?= ./chart
MANIFEST_DIR ?= $(CHART_DIR)/generated

.PHONY: $(APP)
$(APP):
go build .
# shipwright and tekton target versions to download upstream crd resources
SHIPWRIGHT_VERSION ?= v0.11.0
TEKTON_VERSION ?= v0.38.3

build: $(APP)
# full path to the directory where the crds are downloaded
CRD_DIR ?= $(LOCAL_BIN)/crds

# generic arguments used on certain targets
ARGS ?=

.EXPORT_ALL_VARIABLES:

default: build

# ensure that the local "bin" directory exists
$(LOCAL_BIN):
@mkdir -p $(LOCAL_BIN) || true

# builds the primary application executable
.PHONY: $(BIN)
build: $(BIN)
$(BIN): $(LOCAL_BIN)
go build -o $(BIN) .

# downloads shipwright crds from upstream repository
download-crds: $(CRD_DIR)
$(CRD_DIR):
./hack/download-crds.sh

# installs controller-gen in the local bin folder
.PHONY: controller-gen
controller-gen: GOBIN=$(LOCAL_BIN)
controller-gen: $(CONTROLLER_GEN)
$(CONTROLLER_GEN):
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

# generates all Kubernetes releated resources in the project
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) \
rbac:roleName=shipwright-trigger crd paths="./..." \
output:dir=$(MANIFEST_DIR)

# runs the manager from your host
.PHONY: run
run: manifests
go run ./main.go $(ARGS)

# builds the container image with ko without push to registry
.PHONY: container-build
container-build: CGO_ENABLED=0
container-build:
ko build --push=false ${KO_OPTS} .
ko build --push=false $(KO_OPTS) $(ARGS) .

# uses helm to render kubernetes manifests and ko for the container image
.PHONY: deploy
deploy: CGO_ENABLED=0
deploy:
helm template \
--namespace=$(NAMESPACE) \
--set="image.name=ko://github.com/shipwright-io/triggers" \
./chart | \
ko apply ${KO_OPTS} --filename -
shipwright-triggers \
$(CHART_DIR) | \
ko apply $(KO_OPTS) $(ARGS) --filename -

# runs the unit tests, with optional arguments
.PHONY: test-unit
test-unit: CGO_ENABLED=1
test-unit:
go test $(GOFLAGS_TEST) ./...
go test $(GOFLAGS_TEST) $(ARGS) ./pkg/... ./controllers/...

# installs latest envtest-setup, if necessary
.PHONY: envtest
envtest: GOBIN=$(LOCAL_BIN)
envtest: $(ENVTEST)
$(ENVTEST):
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

# run integration tests, with optional arguments
.PHONY: test-integration
test-integration: CGO_ENABLED=1
test-integration: download-crds manifests envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" \
go test $(GOFLAGS_TEST) ./test/integration/... \
-coverprofile=integration.out -ginkgo.v $(ARGS)

# run end-to-end tests
.PHONY: test-e2e
test-e2e:
echo "Not implemented"

.PHONY: verify-kind
verify-kind:
./hack/verify-kind.sh

.PHONY: install-registry
install-registry:
./hack/install-registry.sh

.PHONY: install-shipwright
install-shipwright:
./hack/install-tekton.sh
./hack/install-shipwright.sh
# runs act, with optional arguments
.PHONY: act
act:
@act --secret="GITHUB_TOKEN=${GITHUB_TOKEN}" $(ARGS)
7 changes: 7 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
projectName: triggers
domain: triggers.shipwright.io
repo: github.com/shipwright-io/triggers
layout:
- go.kubebuilder.io/v3
version: "3"
23 changes: 1 addition & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@ Work in progress implementation of [SHIP-0031][SHIP-0031].

## Contributing

To work on this project, consider the following `Makefile` targets:

```bash
# builds the application
make

# run unit-tests
make test-unit

# run end-to-end tests
make test-e2e

# deploy against the controller
make deploy IMAGE_BASE='ghcr.io/...'
```

To work on this project you need the following tools installed:

- GNU/Make
- Helm
- KO
- Kubernetes (`kubectl`)
Please consider the [primary components](./docs/components.md), also how to [build and test](./docs/building.md) this repository.

[SHIP-0031]: https://github.com/shipwright-io/community/blob/main/ships/0031-shipwright-trigger.md
35 changes: 35 additions & 0 deletions chart/generated/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: shipwright-trigger
rules:
- apiGroups:
- shipwright.io
resources:
- buildruns
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- shipwright.io
resources:
- builds
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- pipelineruns
verbs:
- get
- list
- patch
- update
- watch
10 changes: 0 additions & 10 deletions chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "chart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
Expand Down
2 changes: 2 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Common labels
*/}}
{{- define "chart.labels" -}}
helm.sh/chart: {{ include "chart.chart" . }}
meta.helm.sh/release-name: {{ include "chart.fullname" . }}
meta.helm.sh/release-namespace: {{ .Release.Namespace }}
{{ include "chart.selectorLabels" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
Expand Down
19 changes: 13 additions & 6 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: {{ .Release.Namespace }}
name: {{ include "chart.fullname" . }}
labels:
{{- include "chart.labels" . | nindent 4 }}
Expand Down Expand Up @@ -31,18 +32,24 @@ spec:
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.name }}"
args:
- --health-probe-bind-address
- ":{{ .Values.service.probe.port }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
- name: webhook
containerPort: {{ .Values.service.webhook.port }}
protocol: TCP
- name: probe
containerPort: {{ .Values.service.probe.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
path: /healthz
port: probe
readinessProbe:
httpGet:
path: /
port: http
path: /readyz
port: probe
resources:
{{- toYaml .Values.resources | nindent 12 }}
3 changes: 2 additions & 1 deletion chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "chart.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- $svcPort := .Values.service.webhook.port -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: {{ .Release.Namespace }}
name: {{ $fullName }}
labels:
{{- include "chart.labels" . | nindent 4 }}
Expand Down
Loading