Skip to content

Commit

Permalink
Add test.sh test for kubebuilder create config
Browse files Browse the repository at this point in the history
  • Loading branch information
pwittrock committed May 9, 2018
1 parent 6e2f56d commit ba3f578
Showing 1 changed file with 162 additions and 0 deletions.
162 changes: 162 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ function generate_crd_resources {

header_text "editing generated files to simulate a user"
sed -i -e "s|type Bee struct|// +kubebuilder:categories=foo,bar\ntype Bee struct|" pkg/apis/insect/v1beta1/bee_types.go
sed -i -e "s|type BeeController struct {|// +kubebuilder:rbac:groups="",resources=pods,verbs=get;watch;list\ntype BeeController struct {|" pkg/controller/bee/controller.go

header_text "generating and testing CRD definition"
kubebuilder create config --crds --output crd.yaml
kubebuilder create config --controller-image myimage:v1 --name myextensionname --output install.yaml

# Test for the expected generated CRD definition
#
Expand Down Expand Up @@ -212,6 +214,166 @@ status:
EOF
diff crd.yaml expected.yaml

cat << EOF > expected.yaml
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
labels:
api: myextensionname
kubebuilder.k8s.io: $INJECT_KB_VERSION
name: myextensionname-system
spec: {}
status: {}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
labels:
api: myextensionname
kubebuilder.k8s.io: $INJECT_KB_VERSION
name: myextensionname-role
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- watch
- list
- apiGroups:
- insect.sample.kubernetes.io
resources:
- '*'
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: null
labels:
api: myextensionname
kubebuilder.k8s.io: $INJECT_KB_VERSION
name: myextensionname-rolebinding
namespace: myextensionname-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: myextensionname-role
subjects:
- kind: ServiceAccount
name: default
namespace: myextensionname-system
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
api: myextensionname
kubebuilder.k8s.io: $INJECT_KB_VERSION
name: bees.insect.sample.kubernetes.io
spec:
group: insect.sample.kubernetes.io
names:
categories:
- foo
- bar
kind: Bee
plural: bees
scope: Namespaced
validation:
openAPIV3Schema:
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
type: object
status:
type: object
type: object
version: v1beta1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
api: myextensionname
control-plane: controller-manager
kubebuilder.k8s.io: $INJECT_KB_VERSION
name: myextensionname-controller-manager-service
namespace: myextensionname-system
spec:
clusterIP: None
selector:
api: myextensionname
control-plane: controller-manager
kubebuilder.k8s.io: $INJECT_KB_VERSION
status:
loadBalancer: {}
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
creationTimestamp: null
labels:
api: myextensionname
control-plane: controller-manager
kubebuilder.k8s.io: $INJECT_KB_VERSION
name: myextensionname-controller-manager
namespace: myextensionname-system
spec:
replicas: 1
selector:
matchLabels:
api: myextensionname
control-plane: controller-manager
kubebuilder.k8s.io: $INJECT_KB_VERSION
serviceName: myextensionname-controller-manager-service
template:
metadata:
creationTimestamp: null
labels:
api: myextensionname
control-plane: controller-manager
kubebuilder.k8s.io: $INJECT_KB_VERSION
spec:
containers:
- args:
- --install-crds=false
command:
- /root/controller-manager
image: myimage:v1
name: controller-manager
resources:
limits:
cpu: 100m
memory: 30Mi
requests:
cpu: 100m
memory: 20Mi
terminationGracePeriodSeconds: 10
updateStrategy: {}
status:
replicas: 0
EOF
diff -B install.yaml expected.yaml


kubebuilder create resource --group insect --version v1beta1 --kind Wasp
kubebuilder create resource --group ant --version v1beta1 --kind Ant
kubebuilder create config --crds --output crd.yaml
Expand Down

0 comments on commit ba3f578

Please sign in to comment.