Skip to content

Commit

Permalink
staging
Browse files Browse the repository at this point in the history
  • Loading branch information
barney-s committed May 23, 2024
1 parent ac12671 commit 79b33fa
Show file tree
Hide file tree
Showing 14 changed files with 1,165 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/presubmit-compositions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ on:
paths:
- "experiments/**"
jobs:
test-expander-getter:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: "verify expander-getter in a kind cluster"
run: |
./experiments/compositions/scripts/github-actions/getter-test.sh
test-expander-jinja2:
runs-on: ubuntu-latest
timeout-minutes: 20
Expand Down
42 changes: 42 additions & 0 deletions experiments/compositions/composition/Dockerfile.getter.expander
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 Google LLC
#
# 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.

# syntax=docker/dockerfile:1

# ----------------- Build Container ---------------------------
# Build the go app.
# Explicitly set to latest vs golang:1.22
FROM golang:1.22 AS build-stage

# Set destination for COPY
WORKDIR /go/src/app

# Download Go modules
# https://docs.docker.com/reference/dockerfile/#copy
COPY . ./
RUN go mod download

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -v -o expander expanders/getter/main.go

# ----------------- Expander Container ---------------------------
#FROM marketplace.gcr.io/google/debian10:latest as bootstrap
FROM scratch as inline

EXPOSE 8443

WORKDIR /
COPY --from=build-stage /go/src/app/expander .

ENTRYPOINT ["/expander"]
12 changes: 9 additions & 3 deletions experiments/compositions/composition/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ IMG_VERSION ?= v0.0.1
IMG_REGISTRY ?= gcr.io/$(GCP_PROJECT_ID)
IMG ?= $(IMG_REGISTRY)/composition:$(IMG_VERSION)
JINJA_IMG ?= $(IMG_REGISTRY)/expander-jinja2:$(IMG_VERSION)
GETTER_IMG ?= $(IMG_REGISTRY)/expander-getter:$(IMG_VERSION)

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0
Expand Down Expand Up @@ -153,29 +154,34 @@ release-test-cc-manifests: common-test-manifests
cd config/default && $(KUSTOMIZE) edit add patch --namespace system --name controller-manager --kind Deployment --patch "[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/1/args/-\", \"value\": \"--image-registry=gcr.io/$(GCP_PROJECT_ID)\"}]"
cd config/default && $(KUSTOMIZE) edit add patch --namespace system --name controller-manager --kind Deployment --patch "[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/1/imagePullPolicy\", \"value\": \"Always\"}]"
cd config/expanders && $(KUSTOMIZE) edit set image expander-jinja2=${JINJA_IMG}
cd config/expanders && $(KUSTOMIZE) edit set image expander-getter=${GETTER_IMG}
$(KUSTOMIZE) build config/default -o release/test/cc-operator.yaml
cd config/manager && $(KUSTOMIZE) edit set image controller=composition:latest
cd config/default && $(KUSTOMIZE) edit remove patch --namespace system --name controller-manager --kind Deployment --patch "[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/1/args/-\", \"value\": \"--image-registry=gcr.io/$(GCP_PROJECT_ID)\"}]"
cd config/default && $(KUSTOMIZE) edit remove patch --namespace system --name controller-manager --kind Deployment --patch "[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/1/imagePullPolicy\", \"value\": \"Always\"}]"
cd config/expanders && $(KUSTOMIZE) edit set image expander-jinja2=expander-jinja2:latest
cd config/expanders && $(KUSTOMIZE) edit set image expander-getter=expander-getter:latest

.PHONY: release-kind-manifests
release-test-kind-manifests: common-test-manifests
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/expanders && $(KUSTOMIZE) edit set image expander-jinja2=${JINJA_IMG}
cd config/expanders && $(KUSTOMIZE) edit set image expander-getter=${GETTER_IMG}
cd config/default && $(KUSTOMIZE) edit add patch --namespace system --name controller-manager --kind Deployment --patch "[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/1/args/-\", \"value\": \"--image-registry=gcr.io/$(GCP_PROJECT_ID)\"}]"
$(KUSTOMIZE) build config/default -o release/test/kind-operator.yaml
cd config/manager && $(KUSTOMIZE) edit set image controller=composition:latest
cd config/expanders && $(KUSTOMIZE) edit set image expander-jinja2=expander-jinja2:latest
cd config/expanders && $(KUSTOMIZE) edit set image expander-getter=expander-getter:latest
cd config/default && $(KUSTOMIZE) edit remove patch --namespace system --name controller-manager --kind Deployment --patch "[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/1/args/-\", \"value\": \"--image-registry=gcr.io/$(GCP_PROJECT_ID)\"}]"

.PHONY: deploy-kind
deploy-kind: release-test-kind-manifests docker-build docker-build-inline docker-build-expander-jinja2
deploy-kind: release-test-kind-manifests docker-build docker-build-inline docker-build-expander-jinja2 docker-build-expander-getter
kind delete clusters ${KIND_CLUSTER} || true
kind create cluster --name ${KIND_CLUSTER}
kind load docker-image ${IMG} --name ${KIND_CLUSTER}
kind load docker-image ${INLINE_IMG} --name ${KIND_CLUSTER}
kind load docker-image ${JINJA_IMG} --name ${KIND_CLUSTER}
kind load docker-image ${GETTER_IMG} --name ${KIND_CLUSTER}
kubectl --context kind-${KIND_CLUSTER} apply -f release/test/crds.yaml
kubectl --context kind-${KIND_CLUSTER} apply -f release/test/facade_crds.yaml
sleep 5 # for CRDs to be registered
Expand All @@ -184,8 +190,8 @@ deploy-kind: release-test-kind-manifests docker-build docker-build-inline docker
kubectl --context kind-${KIND_CLUSTER} get pods -A

.PHONY: e2e-test
e2e-test: release-test-kind-manifests docker-build docker-build-inline docker-build-expander-jinja2 fmt #docker-push docker-push-inline docker-push-expander-jinja2
cd tests/testcases/ && go test -v -timeout 3600s -run ./... --images=${IMG},${INLINE_IMG},${JINJA_IMG}
e2e-test: release-test-kind-manifests docker-build docker-build-inline docker-build-expander-jinja2 docker-build-expander-getter fmt #docker-push docker-push-inline docker-push-expander-jinja2
cd tests/testcases/ && go test -v -timeout 3600s -run ./... --images=${IMG},${INLINE_IMG},${JINJA_IMG},${GETTER_IMG}

##@ Deployment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ResourceRef struct {
// OPTION 2
Group string `json:"group,omitempty"`
Version string `json:"version,omitempty"`
Resource string `json:"resource"`
Kind string `json:"kind"`
Name string `json:"name,omitempty"`
NameSuffix string `json:"nameSuffix,omitempty"`
Expand All @@ -65,6 +66,10 @@ type Jinja2 struct {
Template string `json:"template"`
}

type Getter struct {
ValuesFrom []ValuesFrom `json:"valuesFrom,omitempty"`
}

// ConfigReference - For BYO Expanders, we can extend it
type ConfigReference struct {
APIGroup string `json:"APIGroup"`
Expand All @@ -73,6 +78,7 @@ type ConfigReference struct {
}
type ExpanderConfig struct {
Jinja2 *Jinja2 `json:"jinja2,omitempty"`
Getter *Getter `json:"getter,omitempty"`

// For BYO Expanders use generic template or ref for external config
Template string `json:"template"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,51 @@ spec:
expanders:
items:
properties:
getter:
properties:
valuesFrom:
items:
properties:
fieldRef:
items:
properties:
as:
type: string
path:
type: string
required:
- as
- path
type: object
type: array
name:
type: string
resourceRef:
properties:
group:
description: OPTION 2
type: string
kind:
type: string
name:
type: string
nameSuffix:
type: string
resource:
type: string
version:
type: string
required:
- kind
- resource
type: object
required:
- fieldRef
- name
- resourceRef
type: object
type: array
type: object
jinja2:
properties:
template:
Expand Down Expand Up @@ -120,10 +165,13 @@ spec:
type: string
nameSuffix:
type: string
resource:
type: string
version:
type: string
required:
- kind
- resource
type: object
required:
- fieldRef
Expand Down
Loading

0 comments on commit 79b33fa

Please sign in to comment.