-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from garethjevans/store-as-crd
feat: implement storage functionality
- Loading branch information
Showing
36 changed files
with
1,891 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: hooks.captainhook.io | ||
labels: | ||
app: {{ template "captain-hook.fullname" . }} | ||
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" | ||
release: "{{ .Release.Name }}" | ||
heritage: "{{ .Release.Service }}" | ||
spec: | ||
group: captainhook.io | ||
names: | ||
kind: Hook | ||
listKind: HookList | ||
plural: hooks | ||
shortNames: | ||
- hook | ||
singular: hook | ||
scope: Namespaced | ||
version: v1alpha1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* | ||
Generated Code | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/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 | ||
|
||
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" | ||
"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}" | ||
"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" | ||
"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" | ||
"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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/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 | ||
|
||
#CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ./cmd/code-generator)} | ||
GENERATOR_VERSION=v0.20.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 get k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}@$GENERATOR_VERSION | ||
) | ||
|
||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | ||
rm -rf "${SCRIPT_ROOT}"/pkg/client | ||
# generate the code with: | ||
# --output-base because this script should also be able to run inside the vendor dir of | ||
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir | ||
# instead of the $GOPATH directly. For normal projects this can be dropped. | ||
bash hack/generate-groups.sh all \ | ||
github.com/garethjevans/captain-hook/pkg/client github.com/garethjevans/captain-hook/pkg/api \ | ||
captainhookio:v1alpha1 \ | ||
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../../.." \ | ||
--go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt | ||
|
||
|
||
#cp -R "${SCRIPT_ROOT}"/v4/pkg/client/ "${SCRIPT_ROOT}"/pkg/client | ||
#cp -R "${SCRIPT_ROOT}"/v4/pkg/apis/jenkins.io/v1/zz_generated.deepcopy.go "${SCRIPT_ROOT}"/pkg/apis/jenkins.io/v1/zz_generated.deepcopy.go | ||
|
||
#rm -rf "${SCRIPT_ROOT}"/v4 | ||
|
||
#bash hack/generate-groups.sh all \ | ||
# github.com/jenkins-x/jx-api/v4/pkg/generated/core github.com/jenkins-x/jx-api/v4/pkg/apis \ | ||
# core:v4beta1 \ | ||
# --output-base "$(dirname "${BASH_SOURCE[0]}")/../../../.." \ | ||
# --go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt | ||
# | ||
# | ||
#cp -R "${SCRIPT_ROOT}"/v4/pkg/generated/ "${SCRIPT_ROOT}"/pkg/generated | ||
#cp -R "${SCRIPT_ROOT}"/v4/pkg/apis/core/v4beta1/zz_generated.deepcopy.go "${SCRIPT_ROOT}"/pkg/apis/core/v4beta1/zz_generated.deepcopy.go | ||
# | ||
#rm -rf "${SCRIPT_ROOT}"/v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package captainhookio | ||
|
||
const ( | ||
// GroupName is the Captain Hook API group name | ||
GroupName = "captainhook.io" | ||
|
||
// Version is the Captain Hook API group version | ||
Version = "v1alpha1" | ||
|
||
// GroupAndVersion is the Captain Hook API Group and version | ||
GroupAndVersion = GroupName + "/" + Version | ||
|
||
// Package is the Go package in which the apis live | ||
Package = "github.com/garethjevans/captain-hook/pkg/api" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// +k8s:deepcopy-gen=package | ||
// +k8s:openapi-gen=true | ||
// +groupName=captainhook.io | ||
package v1alpha1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/garethjevans/captain-hook/pkg/api/captainhookio" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// SchemeGroupVersion is group version used to register these objects. | ||
var SchemeGroupVersion = schema.GroupVersion{Group: captainhookio.GroupName, Version: captainhookio.Version} | ||
|
||
// Kind takes an unqualified kind and returns back a Group qualified GroupKind. | ||
func Kind(kind string) schema.GroupKind { | ||
return SchemeGroupVersion.WithKind(kind).GroupKind() | ||
} | ||
|
||
// Resource takes an unqualified resource and returns a Group qualified GroupResource. | ||
func Resource(resource string) schema.GroupResource { | ||
return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
} | ||
|
||
var ( | ||
// SchemeBuilder for building the schema :). | ||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) | ||
// AddToScheme helper | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) | ||
|
||
func init() { | ||
// We only register manually written functions here. The registration of the | ||
// generated functions takes place in the generated files. The separation | ||
// makes the code compile even when the generated files are missing. | ||
SchemeBuilder.Register(addKnownTypes) | ||
} | ||
|
||
// Adds the list of known types to Scheme. | ||
func addKnownTypes(scheme *runtime.Scheme) error { | ||
scheme.AddKnownTypes(SchemeGroupVersion, | ||
&Hook{}, | ||
&HookList{}, | ||
) | ||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion) | ||
return nil | ||
} | ||
|
||
type ResourceReference struct { | ||
// API version of the referent. | ||
APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,5,opt,name=apiVersion"` | ||
// Kind of the referent. | ||
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds | ||
Kind string `json:"kind" protobuf:"bytes,1,opt,name=kind"` | ||
// Name of the referent. | ||
// More info: http://kubernetes.io/docs/user-guide/identifiers#names | ||
Name string `json:"name" protobuf:"bytes,3,opt,name=name"` | ||
// UID of the referent. | ||
// More info: http://kubernetes.io/docs/user-guide/identifiers#uids | ||
UID types.UID `json:"uid,omitempty" protobuf:"bytes,4,opt,name=uid,casttype=k8s.io/apimachinery/pkg/types.UID"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// +genclient | ||
// +genclient:noStatus | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
// +k8s:openapi-gen=true | ||
|
||
// Hook represents a webhook. | ||
type Hook struct { | ||
metav1.TypeMeta `json:",inline"` | ||
// Standard object's metadata. | ||
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata | ||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` | ||
|
||
Spec HookSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` | ||
Status HookStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` | ||
} | ||
|
||
// HookSpec is the specification of a Hook. | ||
type HookSpec struct { | ||
ForwardURL string `json:"forwardURL" protobuf:"bytes,1,opt,name=forwardURL"` | ||
Body string `json:"body" protobuf:"bytes,2,opt,name=body"` | ||
Headers map[string][]string `json:"headers,omitempty" protobuf:"bytes,3,opt,name=headers"` | ||
} | ||
|
||
// HookStatus is the status for a Hook resource. | ||
type HookStatus struct { | ||
Status HookStatusType `json:"status,omitempty" protobuf:"bytes,1,opt,name=status"` | ||
Attempts int `json:"attempts,omitempty" protobuf:"bytes,2,opt,name=attempts"` | ||
Message string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"` | ||
} | ||
|
||
// HookStatusType is the status of a hook; usually success or failed at completion. | ||
type HookStatusType string | ||
|
||
const ( | ||
// HookStatusTypeNone an hook step has not started yet. | ||
HookStatusTypeNone HookStatusType = "" | ||
// HookStatusTypePending the hook currently being relayed. | ||
HookStatusTypePending HookStatusType = "Pending" | ||
// HookStatusTypeStatus the hook has been relayed. | ||
HookStatusTypeSuccess HookStatusType = "Success" | ||
// ReleaseStatusTypeFailed the hook has failed to be relayed. | ||
HookStatusTypeFailed HookStatusType = "Failed" | ||
) | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// HookList is a list of TypeMeta resources. | ||
type HookList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata"` | ||
|
||
Items []Hook `json:"items"` | ||
} |
Oops, something went wrong.