Skip to content

Commit

Permalink
Import OpenShiftPipelineAsCode
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Mar 14, 2023
1 parent 64da7c5 commit 460bcb2
Show file tree
Hide file tree
Showing 267 changed files with 79,109 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.gopath
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ This is the repository of a *proof-of-concept* of OpenShift Operator based of th

- [x] Import `cmd/…`
- [x] Import `config/…`
- [ ] Import `openshift` specific package
- [ ] GitHub workflows
- [ ] Create `v1beta1.OpenShiftPipelineConfig` to *replace* `TektonConfig`
- [ ] openshift-ci for tests
- [x] Import `openshift` specific package
- [x] GitHub workflows
- [ ] Import `OpenShiftPipelineAsCode` in here
- [ ] `Makefile`
- [ ] Automated/scripted import payload (copy from tektoncd/operator)
- [ ] Automated/scripted import `tektoncd/operator` CRDs
- [ ] e2e tests
Run upstream ones, import "and forget" ?
- [ ] Handle "component" *payload* images rebuild
- We can use the upstream images…
- but we could also *rebuild them all*, to be even closer to
downstream. The question is how ?
- [ ] Create `v1beta1.OpenShiftPipelineConfig` to *replace* `TektonConfig`
- [ ] openshift-ci for tests
- [ ] Remove openshift specifics from upstream
15 changes: 7 additions & 8 deletions config/300-operator_v1alpha1_openshiftpipelinesascode_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: openshiftpipelinesascodes.operator.tekton.dev
name: pipelinesascodes.operator.openshift-pipelines.org
labels:
version: "devel"
operator.tekton.dev/release: "devel"
spec:
group: operator.tekton.dev
group: operator.openshift-pipelines.org
names:
kind: OpenShiftPipelinesAsCode
listKind: OpenShiftPipelinesAsCodeList
plural: openshiftpipelinesascodes
singular: openshiftpipelinesascode
kind: PipelinesAsCode
listKind: PipelinesAsCodeList
plural: pipelinesascodes
singular: pipelinesascode
shortNames:
- opac
- pac
preserveUnknownFields: false
scope: Cluster
Expand All @@ -50,5 +49,5 @@ spec:
schema:
openAPIV3Schema:
type: object
description: Schema for the OpenShiftPipelinesAsCode API
description: Schema for the PipelinesAsCode API
x-kubernetes-preserve-unknown-fields: true
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ require (
github.com/manifestival/controller-runtime-client v0.4.0
github.com/manifestival/manifestival v0.7.2
github.com/markbates/inflect v1.0.4
github.com/openshift-pipelines/pipelines-as-code v0.16.0
github.com/openshift/api v0.0.0-20210910062324-a41d3573a3ba
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142
github.com/tektoncd/operator v0.65.1
github.com/tektoncd/pipeline v0.44.0
github.com/tektoncd/plumbing v0.0.0-20230309231045-dbb204980ea8
github.com/tektoncd/triggers v0.22.1
go.uber.org/zap v1.24.0
gomodules.xyz/jsonpatch/v2 v2.2.0
Expand All @@ -21,6 +23,7 @@ require (
k8s.io/apiextensions-apiserver v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/code-generator v0.26.1
knative.dev/pkg v0.0.0-20230310210124-b769fef17fa3
sigs.k8s.io/controller-runtime v0.13.1
sigs.k8s.io/yaml v1.3.0
Expand Down Expand Up @@ -85,7 +88,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/openshift-pipelines/pipelines-as-code v0.16.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
Expand All @@ -112,6 +114,7 @@ require (
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.5.0 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230209215440-0dfe4f8abfcc // indirect
Expand All @@ -121,6 +124,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo v0.0.0-20221011193443-fad74ee6edd9 // indirect
k8s.io/klog/v2 v2.90.0 // indirect
k8s.io/kube-openapi v0.0.0-20230123231816-1cb3ae25d79a // indirect
k8s.io/utils v0.0.0-20230115233650-391b47cb4029 // indirect
Expand Down
428 changes: 428 additions & 0 deletions go.sum

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions hack/boilerplate/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2023 The OpenShift Pipelines Authors

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.
*/
94 changes: 94 additions & 0 deletions hack/generate-groups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

# Copyright 2017 The Kubernetes Authors.
#
# 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.

set -o errexit
set -o nounset
set -o pipefail


# generate-groups generates everything for a project with external types only, e.g. a project based
# on CustomResourceDefinitions.

if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then
cat <<EOF
Usage: $(basename "$0") <generators> <output-package> <apis-package> <groups-versions> ...
<generators> the generators comma separated to run (deepcopy,defaulter,client,lister,informer) or "all".
<output-package> the output package name (e.g. github.com/example/project/pkg/generated).
<apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis).
<groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
to <api-package>.
... arbitrary flags passed to all generator binaries.
Examples:
$(basename "$0") all github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1"
$(basename "$0") deepcopy,client github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1"
EOF
exit 0
fi

GENS="$1"
OUTPUT_PKG="$2"
APIS_PKG="$3"
GROUPS_WITH_VERSIONS="$4"
shift 4

(
# To support running this script from anywhere, we have to first cd into this directory
# so we can install the tools.
cd "$(dirname "${0}")"
go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
)

set -x

PREFIX=${GOBIN:-${GOPATH}/bin}

function codegen::join() { local IFS="$1"; shift; echo "$*"; }

# enumerate group versions
FQ_APIS=() # e.g. k8s.io/api/apps/v1
for GVs in ${GROUPS_WITH_VERSIONS}; do
IFS=: read -r G Vs <<<"${GVs}"

# enumerate versions
for V in ${Vs//,/ }; do
FQ_APIS+=("${APIS_PKG}/${G}/${V}")
done
done

if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
echo "Generating deepcopy funcs for ${GROUPS_WITH_VERSIONS}"
"${PREFIX}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
"${PREFIX}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${PREFIX}/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
"${PREFIX}/informer-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
--listers-package "${OUTPUT_PKG}/listers" \
--output-package "${OUTPUT_PKG}/informers" \
"$@"
fi
98 changes: 98 additions & 0 deletions hack/generate-knative.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

# Copyright 2019 The Knative Authors.
#
# 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.

set -o errexit
set -o nounset
set -o pipefail

# generate-groups generates everything for a project with external types only, e.g. a project based
# on CustomResourceDefinitions.

if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then
cat <<EOF
Usage: $(basename $0) <generators> <client-package> <apis-package> <groups-versions> ...
<generators> the generators comma separated to run (deepcopy,defaulter,client,lister,informer) or "all".
<client-package> the client package dir (e.g. github.com/example/project/pkg/clientset).
<apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis).
<groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
to <api-package>.
... arbitrary flags passed to all generator binaries.
Examples:
$(basename $0) all github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1"
$(basename $0) injection,foo github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1"
EOF
exit 0
fi

GENS="$1"
CLIENT_PKG="$2"
APIS_PKG="$3"
GROUPS_WITH_VERSIONS="$4"
shift 4

(
# To support running this script from anywhere, we have to first cd into this directory
# so we can install the tools.
cd $(dirname "${0}")
go install knative.dev/pkg/codegen/cmd/injection-gen
)

PREFIX=${GOBIN:-${GOPATH}/bin}

function codegen::join() { local IFS="$1"; shift; echo "$*"; }

# enumerate group versions
FQ_APIS=() # e.g. k8s.io/api/apps/v1
for GVs in ${GROUPS_WITH_VERSIONS}; do
IFS=: read G Vs <<<"${GVs}"

# enumerate versions
for V in ${Vs//,/ }; do
FQ_APIS+=(${APIS_PKG}/${G}/${V})
done
done


if grep -qw "injection" <<<"${GENS}"; then
if [[ -z "${OUTPUT_PKG:-}" ]]; then
OUTPUT_PKG="${CLIENT_PKG}/injection"
fi

if [[ -z "${VERSIONED_CLIENTSET_PKG:-}" ]]; then
VERSIONED_CLIENTSET_PKG="${CLIENT_PKG}/clientset/versioned"
fi

if [[ -z "${EXTERNAL_INFORMER_PKG:-}" ]]; then
EXTERNAL_INFORMER_PKG="${CLIENT_PKG}/informers/externalversions"
fi

if [[ -z "${LISTERS_PKG:-}" ]]; then
LISTERS_PKG="${CLIENT_PKG}/listers"
fi

echo "Generating injection for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}"

# Clear old injection
rm -rf ${OUTPUT_PKG}

${PREFIX}/injection-gen \
--input-dirs $(codegen::join , "${FQ_APIS[@]}") \
--versioned-clientset-package ${VERSIONED_CLIENTSET_PKG} \
--external-versions-informers-package ${EXTERNAL_INFORMER_PKG} \
--listers-package ${LISTERS_PKG} \
--output-package ${OUTPUT_PKG} \
"$@"
fi
85 changes: 85 additions & 0 deletions hack/setup-temporary-gopath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

# Conditionally create a temporary GOPATH for codegen
# and openapigen to execute in. This is only done if
# the current repo directory is not within GOPATH.
function shim_gopath() {
local REPO_DIR=$(git rev-parse --show-toplevel)
local TEMP_GOPATH="${REPO_DIR}/.gopath"
local TEMP_TEKTONCD="${TEMP_GOPATH}/src/github.com/openshift-pipelines"
local TEMP_OPERATOR="${TEMP_TEKTONCD}/operator"
local NEEDS_MOVE=1

# Checks if GOPATH exists without triggering nounset panic.
EXISTING_GOPATH=${GOPATH:-}

# Check if repo is in GOPATH already and return early if so.
# Unfortunately this doesn't respect a repo that's symlinked into
# GOPATH and will create a temporary anyway. I couldn't figure out
# a way to get the absolute path to the symlinked repo root.
if [ ! -z $EXISTING_GOPATH ] ; then
case $REPO_DIR/ in
$EXISTING_GOPATH/*) NEEDS_MOVE=0;;
*) NEEDS_MOVE=1;;
esac
fi

if [ $NEEDS_MOVE -eq 0 ]; then
return
fi

echo "You appear to be running from outside of GOPATH."
echo "This script will create a temporary GOPATH at $TEMP_GOPATH for code generation."

# Ensure that the temporary pipelines symlink doesn't exist
# before proceeding.
delete_pipeline_repo_symlink

mkdir -p "$TEMP_TEKTONCD"
# This will create a symlink from
# (repo-root)/.gopath/src/github.com/tektoncd/operator
# to the user's pipeline checkout.
ln -s "$REPO_DIR" "$TEMP_TEKTONCD"
echo "Moving to $TEMP_OPERATOR"
cd "$TEMP_OPERATOR"
export GOPATH="$TEMP_GOPATH"
}

# Helper that wraps deleting the temp pipelines repo symlink
# and prints a message about deleting the temp GOPATH.
#
# Why doesn't this func just delete the temp GOPATH outright?
# Because it might be reused across multiple hack scripts and many
# packages seem to be installed into GOPATH with read-only
# permissions, requiring sudo to delete the directory. Rather
# than surprise the dev with a password entry at the end of the
# script's execution we just print a message to let them know.
function shim_gopath_clean() {
local REPO_DIR=$(git rev-parse --show-toplevel)
local TEMP_GOPATH="${REPO_DIR}/.gopath"
if [ -d "$TEMP_GOPATH" ] ; then
# Put the user back at the root of the pipelines repo
# after all the symlink shenanigans.
echo "Moving to $REPO_DIR"
cd "$REPO_DIR"
delete_pipeline_repo_symlink
echo "When you are finished with codegen you can safely run the following:"
echo "sudo rm -rf \".gopath\""
fi
}

# Delete the temp symlink to pipelines repo from the temp GOPATH dir.
function delete_pipeline_repo_symlink() {
local REPO_DIR=$(git rev-parse --show-toplevel)
local TEMP_GOPATH="${REPO_DIR}/.gopath"
if [ -d "$TEMP_GOPATH" ] ; then
local REPO_SYMLINK="${TEMP_GOPATH}/src/github.com/tektoncd/pipeline"
if [ -L $REPO_SYMLINK ] ; then
echo "Deleting symlink to pipelines repo $REPO_SYMLINK"
rm -f "${REPO_SYMLINK}"
fi
fi
}
Loading

0 comments on commit 460bcb2

Please sign in to comment.