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

Add Conditionals via CEL, change name of repo #2

Merged
merged 70 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9737cae
Require string and math transform types
negz Oct 3, 2023
c270557
Merge pull request #16 from negz/erroneous
negz Oct 11, 2023
584c44a
Flip want and got in fn_test.go
negz Oct 5, 2023
b354298
Patch to and from an Environment loaded from Function context
negz Oct 5, 2023
e91e41d
Mention that environment-related fields are alpha.
negz Oct 16, 2023
26ac07a
Log when we load the environment
negz Oct 16, 2023
146bc70
Merge pull request #17 from negz/contextual
negz Oct 18, 2023
6716333
change list toType to array
stevendborrelli Oct 20, 2023
bf1accf
Merge pull request #22 from stevendborrelli/4825-array
negz Oct 20, 2023
8a269ba
Setup GitHub Actions
negz Oct 20, 2023
b536058
Merge pull request #23 from negz/continuous
negz Oct 20, 2023
ff29189
Remove codeql
negz Oct 20, 2023
a22772a
Remove PPC target
negz Oct 20, 2023
c9a5c30
Fix linter sadness
negz Oct 20, 2023
78fbc00
Use the GitHub Actions Docker build cache backend
negz Oct 21, 2023
50da619
Don't setup Go for the package build
negz Oct 21, 2023
ed116ba
Tweak Docker caching
negz Oct 21, 2023
95dee53
Build an xpkg
negz Oct 21, 2023
b9c3273
Use Go's native cross-compile support instead of emulation
negz Oct 22, 2023
8ed5989
Pass runtime image as a tarball instead
negz Oct 22, 2023
0aaa738
Load packages into a separate push stage
negz Oct 22, 2023
55b1c4f
WIP: Push multi-arch package
negz Oct 22, 2023
ecb249f
Push a multi-platform package
negz Oct 22, 2023
a751115
Checkout the repo in the push job
negz Oct 22, 2023
96d11c4
Use 'access ID' and 'token' to better describe credentials
negz Oct 22, 2023
ac00fd0
Remove redundant repo owner from package name
negz Oct 22, 2023
46f2fbc
Merge pull request #24 from negz/continuous
negz Oct 22, 2023
1ec551e
Don't build an amd64 binary in the arm64 image
negz Oct 23, 2023
c5ccac5
Merge pull request #25 from negz/continuous
negz Oct 23, 2023
04c3eb7
evaluate expressions with cel
stevendborrelli Oct 23, 2023
2ca7c04
use new sdk fork module
stevendborrelli Oct 23, 2023
8c4eb9c
fix linter errors
stevendborrelli Oct 23, 2023
23bdd38
gci import update
stevendborrelli Oct 23, 2023
1b5ba1c
add test for conditionals
stevendborrelli Oct 24, 2023
3a30fd5
improve type error message
stevendborrelli Oct 24, 2023
e6b16ed
update examples with reand nop provider
stevendborrelli Oct 25, 2023
155a4b3
update go.mod for function-sdk-go updates
stevendborrelli Oct 25, 2023
df2c9da
Setup Renovate
negz Nov 1, 2023
8d93ab2
Merge pull request #28 from negz/release-prep
negz Nov 1, 2023
6c096af
Update kubernetes packages to v0.28.3
renovate[bot] Nov 1, 2023
fef9a2f
Merge pull request #30 from crossplane-contrib/renovate/kubernetes-go
negz Nov 1, 2023
f286d4a
Update module github.com/alecthomas/kong to v0.8.1
renovate[bot] Nov 1, 2023
aed1771
Merge pull request #32 from crossplane-contrib/renovate/github.com-al…
negz Nov 1, 2023
02ea9f5
Bump k8s.io/utils
negz Nov 1, 2023
8ede59a
Merge pull request #36 from negz/release-prep
negz Nov 1, 2023
17e5630
Bump to controller-tools v0.13.0
negz Nov 1, 2023
f39dac6
Merge pull request #37 from negz/release-prep
negz Nov 1, 2023
036c9db
Update module github.com/crossplane/function-sdk-go to v0.1.0
renovate[bot] Nov 1, 2023
4bb9201
Merge pull request #34 from crossplane-contrib/renovate/github.com-cr…
negz Nov 1, 2023
9a69a54
Use Go style pseudo-versions when there is no semver supplied details.
negz Nov 1, 2023
6016fe0
Merge pull request #38 from negz/release-prep
negz Nov 1, 2023
ec96a6d
Slim down the README
negz Nov 1, 2023
304ca8f
Merge pull request #39 from negz/release-prep
negz Nov 2, 2023
d41ba66
Update module github.com/crossplane/crossplane-runtime to v1.14.1
renovate[bot] Nov 2, 2023
bf14741
Merge pull request #33 from crossplane-contrib/renovate/github.com-cr…
negz Nov 2, 2023
f78ce06
Add useful package metadata
negz Nov 3, 2023
744e975
Merge pull request #40 from negz/meta
negz Nov 3, 2023
8055479
Add useful package metadata
negz Nov 3, 2023
56360cf
Fix package metadata
negz Nov 3, 2023
7b012af
Merge pull request #42 from negz/meta
negz Nov 3, 2023
2621e5b
Fix package metadata
negz Nov 3, 2023
bd93725
Merge pull request #43 from negz/release-0.2-meta
negz Nov 3, 2023
4aecf5b
Fix typos in the package metadata
negz Nov 3, 2023
e2fccaf
Merge pull request #45 from negz/meta
negz Nov 3, 2023
1feed87
feat: :wrench: eval CEL expression for each composed resource
Nov 13, 2023
a36244b
Merge pull request #1 from jcooklin/pr/stevendborrelli/26
stevendborrelli Nov 14, 2023
0b35fb6
merge upstream main
stevendborrelli Nov 14, 2023
f4bba8d
update repo location
stevendborrelli Nov 14, 2023
20b2fce
lint fixes
stevendborrelli Nov 14, 2023
a0618e5
lint fixes
stevendborrelli Nov 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: CI

on:
push:
branches:
- main
- release-*
pull_request: {}
workflow_dispatch:
inputs:
version:
description: Package version (e.g. v0.1.0)
required: false

env:
# Common versions
GO_VERSION: '1.21.3'
GOLANGCI_VERSION: 'v1.54.2'
DOCKER_BUILDX_VERSION: 'v0.11.2'

# These environment variables are important to the Crossplane CLI install.sh
# script. They determine what version it installs.
XP_CHANNEL: master # TODO(negz): Pin to stable once v1.14 is released.
XP_VERSION: current # TODO(negz): Pin to a version once v1.14 is released.

# This CI job will automatically push new builds to xpkg.upbound.io if the
# XPKG_ACCESS_ID and XPKG_TOKEN secrets are set in the GitHub respository (or
# organization) settings. Create a token at https://accounts.upbound.io.
XPKG_ACCESS_ID: ${{ secrets.XPKG_ACCESS_ID }}

# The package to push, without a version tag. The default matches GitHub. For
# example xpkg.upbound.io/crossplane/function-template-go.
XPKG: xpkg.upbound.io/${{ github.repository}}

# The package version to push. The default is 0.0.0-gitsha.
XPKG_VERSION: ${{ inputs.version }}

jobs:
lint:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache: false # The golangci-lint action does its own caching.

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCI_VERSION }}

unit-test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Run Unit Tests
run: go test -v -cover ./...

# We want to build most packages for the amd64 and arm64 architectures. To
# speed this up we build single-platform packages in parallel. We then upload
# those packages to GitHub as a build artifact. The push job downloads those
# artifacts and pushes them as a single multi-platform package.
build:
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
arch:
- amd64
- arm64
steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true

- name: Checkout
uses: actions/checkout@v4

# We ask Docker to use GitHub Action's native caching support to speed up
# the build, per https://docs.docker.com/build/cache/backends/gha/.
- name: Build Runtime
id: image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: image
build-args:
GO_VERSION=${{ env.GO_VERSION }}
outputs: type=docker,dest=runtime-${{ matrix.arch }}.tar

- name: Setup the Crossplane CLI
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"

- name: Build Package
run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar

- name: Upload Single-Platform Package
uses: actions/upload-artifact@v3
with:
name: packages
path: "*.xpkg"
if-no-files-found: error
retention-days: 1

# This job downloads the single-platform packages built by the build job, and
# pushes them as a multi-platform package. We only push the package it the
# XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
push:
runs-on: ubuntu-22.04
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download Single-Platform Packages
uses: actions/download-artifact@v3
with:
name: packages
path: .

- name: Setup the Crossplane CLI
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"

- name: Login to Upbound
uses: docker/login-action@v3
if: env.XPKG_ACCESS_ID != ''
with:
registry: xpkg.upbound.io
username: ${{ secrets.XPKG_ACCESS_ID }}
password: ${{ secrets.XPKG_TOKEN }}

# If a version wasn't explicitly passed as a workflow_dispatch input we
# default to version v0.0.0-<git-commit-date>-<git-short-sha>, for example
# v0.0.0-20231101115142-1091066df799. This is a simple implementation of
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
- name: Set Default Multi-Platform Package Version
if: env.XPKG_VERSION == ''
run: echo "XPKG_VERSION=v0.0.0-$(date -d@$(git show -s --format=%ct) +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" >> $GITHUB_ENV

- name: Push Multi-Platform Package to Upbound
if: env.XPKG_ACCESS_ID != ''
run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}"
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ linters-settings:
- default
- prefix(github.com/crossplane/crossplane-runtime)
- prefix(github.com/crossplane/function-sdk-go)
- prefix(github.com/crossplane-contrib/function-patch-and-transform)
- prefix(github.com/stevendborrelli/function-conditional-patch-and-transform)
- blank
- dot

Expand Down
53 changes: 23 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
FROM golang:1.20 as build-stage
# syntax=docker/dockerfile:1

WORKDIR /fn

COPY go.mod go.sum ./
RUN go mod download

COPY input/ ./input
COPY *.go ./

RUN CGO_ENABLED=0 go build -o /function .

FROM debian:12.1-slim as package-stage

# TODO(negz): Use a proper Crossplane package building tool. We're abusing the
# fact that this image won't have an io.crossplane.pkg: base annotation. This
# means Crossplane package manager will pull this entire ~100MB image, which
# also happens to contain a valid Function runtime.
# https://github.com/crossplane/crossplane/blob/v1.13.2/contributing/specifications/xpkg.md
WORKDIR /package
COPY package/ ./
# We use the latest Go 1.x version unless asked to use something else.
ARG GO_VERSION=1

RUN cat crossplane.yaml > /package.yaml
RUN cat input/*.yaml >> /package.yaml
# Setup the base environment.
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base

FROM gcr.io/distroless/base-debian11 AS build-release-stage
WORKDIR /fn
ENV CGO_ENABLED=0

COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download

# Build the Function.
FROM base AS build
ARG TARGETOS
ARG TARGETARCH
RUN --mount=target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /function .

# Produce the Function image.
FROM gcr.io/distroless/base-debian11 AS image
WORKDIR /

COPY --from=build-stage /function /function
COPY --from=package-stage /package.yaml /package.yaml

COPY --from=build /function /function
EXPOSE 9443

USER nonroot:nonroot

ENTRYPOINT ["/function"]
ENTRYPOINT ["/function"]
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

DOCKER := docker
GO := go

GOLANGCI_VERSION := 1.55.2

test:
$(GO) test ./...

lint:
$(DOCKER) run --rm -v $(CURDIR):/app -v ~/.cache/golangci-lint/v$(GOLANGCI_VERSION):/root/.cache -w /app golangci/golangci-lint:v$(GOLANGCI_VERSION) golangci-lint run --fix

reviewable: test lint
Loading