Skip to content

Commit b8cb25c

Browse files
committed
Initial version
1 parent 9e04f47 commit b8cb25c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3866
-0
lines changed

cmd/pizza-crd-webhook/main.go

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"net/http"
21+
"os"
22+
"time"
23+
24+
"github.com/spf13/pflag"
25+
"k8s.io/apiserver/pkg/server"
26+
"k8s.io/apiserver/pkg/server/options"
27+
28+
"github.com/programming-kubernetes/pizza-crd/pkg/webhook/conversion"
29+
)
30+
31+
func NewDefaultOptions() *Options {
32+
o := &Options{
33+
*options.NewSecureServingOptions(),
34+
}
35+
o.SecureServing.ServerCert.PairName = "pizza-crd-webhook"
36+
return o
37+
}
38+
39+
type Options struct {
40+
SecureServing options.SecureServingOptions
41+
}
42+
43+
type Config struct {
44+
SecureServing *server.SecureServingInfo
45+
}
46+
47+
func (o *Options) AddFlags(fs *pflag.FlagSet) {
48+
o.SecureServing.AddFlags(fs)
49+
}
50+
51+
func (o *Options) Config() (*Config, error) {
52+
if err := o.SecureServing.MaybeDefaultWithSelfSignedCerts("0.0.0.0", nil, nil); err != nil {
53+
return nil, err
54+
}
55+
56+
c := &Config{}
57+
58+
if err := o.SecureServing.ApplyTo(&c.SecureServing); err != nil {
59+
return nil, err
60+
}
61+
62+
return c, nil
63+
}
64+
65+
func main() {
66+
// parse flags
67+
opt := NewDefaultOptions()
68+
fs := pflag.NewFlagSet("pizza-crd-webhook", pflag.ExitOnError)
69+
opt.AddFlags(fs)
70+
if err := fs.Parse(os.Args); err != nil {
71+
panic(err)
72+
}
73+
74+
// create runtime config
75+
cfg, err := opt.Config()
76+
if err != nil {
77+
panic(err)
78+
}
79+
80+
// run server
81+
mux := http.NewServeMux()
82+
mux.Handle("/convert/pizza", http.HandlerFunc(conversion.Serve))
83+
if doneCh, err := cfg.SecureServing.Serve(mux, time.Second * 30, server.SetupSignalHandler()); err != nil {
84+
panic(err)
85+
} else {
86+
<-doneCh
87+
}
88+
}

glide.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package: github.com/programming-kubernetes/pizza-crd
2+
import:
3+
- package: k8s.io/apiserver
4+
version: kubernetes-1.14.1
5+
- package: k8s.io/client-go
6+
version: kubernetes-1.14.1
7+
- package: k8s.io/code-generator
8+
version: kubernetes-1.14.1
9+
- package: k8s.io/apiextensions-apiserver
10+
version: kubernetes-1.14.1
11+
12+
# pin gonum because the old redirect gonum.org/v1/gonum is broken
13+
- package: gonum.org/v1/gonum
14+
version: 5d695651a1d533b5b371458b6da17b45c17ed718
15+
repo: https://github.com/gonum/gonum.git

hack/boilerplate.go.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Copyright The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+

hack/custom-boilerplate.go.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Copyright YEAR The Kubernetes custom-apiserver Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+

hack/tools.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// +build tools
2+
3+
/*
4+
Copyright 2019 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
// This package imports things required by build scripts, to force `go mod` to see them as dependencies
20+
package tools
21+
22+
import (
23+
_ "k8s.io/code-generator"
24+
_ "k8s.io/code-generator/cmd/client-gen"
25+
_ "k8s.io/code-generator/cmd/conversion-gen"
26+
_ "k8s.io/code-generator/cmd/deepcopy-gen"
27+
_ "k8s.io/code-generator/cmd/defaulter-gen"
28+
_ "k8s.io/code-generator/cmd/go-to-protobuf"
29+
_ "k8s.io/code-generator/cmd/informer-gen"
30+
_ "k8s.io/code-generator/cmd/lister-gen"
31+
_ "k8s.io/code-generator/cmd/register-gen"
32+
)

hack/update-codegen.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2017 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
22+
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
23+
24+
# generate the code with:
25+
# --output-base because this script should also be able to run inside the vendor dir of
26+
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
27+
# instead of the $GOPATH directly. For normal projects this can be dropped.
28+
bash ${CODEGEN_PKG}/generate-groups.sh all \
29+
github.com/programming-kubernetes/pizza-crd/pkg/generated github.com/programming-kubernetes/pizza-crd/pkg/apis \
30+
"restaurant:v1alpha1,v1beta1" \
31+
--output-base "$(dirname ${BASH_SOURCE})/../../../.." \
32+
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt
33+
34+
# To use your own boilerplate text use:
35+
# --go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt

hack/verify-codegen.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2017 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/..
22+
SCRIPT_BASE=${SCRIPT_ROOT}/../..
23+
24+
DIFFROOT="${SCRIPT_ROOT}/pkg"
25+
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg"
26+
_tmp="${SCRIPT_ROOT}/_tmp"
27+
28+
cleanup() {
29+
rm -rf "${_tmp}"
30+
}
31+
trap "cleanup" EXIT SIGINT
32+
33+
cleanup
34+
35+
mkdir -p "${TMP_DIFFROOT}"
36+
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"
37+
38+
"${SCRIPT_ROOT}/hack/update-codegen.sh"
39+
echo "diffing ${DIFFROOT} against freshly generated codegen"
40+
ret=0
41+
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
42+
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}"
43+
if [[ $ret -eq 0 ]]
44+
then
45+
echo "${DIFFROOT} up to date."
46+
else
47+
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh"
48+
exit 1
49+
fi

manifests/margarita-pizza.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: restaurant.programming-kubernetes.info/v1alpha1
2+
kind: Pizza
3+
metadata:
4+
name: margarita
5+
spec:
6+
toppings:
7+
- mozzarella
8+
- tomato

manifests/pizza-crd.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: pizzas.restaurant.programming-kubernetes.info
5+
spec:
6+
group: restaurant.programming-kubernetes.info
7+
names:
8+
kind: Pizza
9+
listKind: PizzaList
10+
plural: pizzas
11+
singular: pizza
12+
scope: Namespaced
13+
version: v1alpha1
14+
versions:
15+
- name: v1alpha1
16+
served: true
17+
storage: true
18+
- name: v1beta1
19+
served: true
20+
storage: false
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package install
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime"
21+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
22+
23+
"github.com/programming-kubernetes/pizza-crd/pkg/apis/restaurant/v1alpha1"
24+
"github.com/programming-kubernetes/pizza-crd/pkg/apis/restaurant/v1beta1"
25+
)
26+
27+
// Install registers the API group and adds types to a scheme
28+
func Install(scheme *runtime.Scheme) {
29+
utilruntime.Must(v1beta1.AddToScheme(scheme))
30+
utilruntime.Must(v1alpha1.AddToScheme(scheme))
31+
}

pkg/apis/restaurant/v1alpha1/doc.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=package
18+
// +k8s:conversion-gen=github.com/programming-kubernetes/pizza-crd/pkg/apis/restaurant
19+
// +k8s:defaulter-gen=TypeMeta
20+
// +groupName=restaurant.programming-kubernetes.info
21+
22+
// Package v1alpha1 is the v1alpha1 version of the API.
23+
package v1alpha1

0 commit comments

Comments
 (0)