Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mingfang/kubernetes-crd-test

To test various Kubernetes CRD configurations
https://github.com/mingfang/kubernetes-crd-test

Last synced: about 5 hours ago
JSON representation

To test various Kubernetes CRD configurations

Awesome Lists containing this project

README

        

# kubernetes-crd-test
To test various Kubernetes CRD configurations.

## Requirements to run the tests
- Kubernetes v1.14 with ```--feature-gates=CustomResourcePublishOpenAPI=true``` as documented here https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#publish-validation-schema-in-openapi-v2
- kubectl v1.14

## Test Case #1
Basic CRD without any openAPI spec
```yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
version: v1
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
```
```sh
>sh -x test.sh crontab-crd-no-spec.yaml
+ kubectl delete crontabs --all --ignore-not-found=true
No resources found
+ kubectl delete crd crontabs.stable.example.com --ignore-not-found=true
customresourcedefinition.apiextensions.k8s.io "crontabs.stable.example.com" deleted
+ kubectl apply -f crontab-crd-no-spec.yaml
customresourcedefinition.apiextensions.k8s.io/crontabs.stable.example.com created
+ sleep 3
+ kubectl explain crontab --recursive
KIND: CronTab
VERSION: stable.example.com/v1

DESCRIPTION:

```

## Test Case #2
CRD with openAPI but spec type not set to anything
```yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
version: v1
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
validation:
openAPIV3Schema:
properties:
spec:
properties:
cronSpec:
type: string
pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
replicas:
type: integer
minimum: 1
maximum: 10
```
```sh
>sh -x test.sh crontab-crd-non-object-spec.yaml
+ kubectl delete crontabs --all --ignore-not-found=true
No resources found
+ kubectl delete crd crontabs.stable.example.com --ignore-not-found=true
customresourcedefinition.apiextensions.k8s.io "crontabs.stable.example.com" deleted
+ kubectl apply -f crontab-crd-non-object-spec.yaml
customresourcedefinition.apiextensions.k8s.io/crontabs.stable.example.com created
+ sleep 3
+ kubectl explain crontab --recursive
KIND: CronTab
VERSION: stable.example.com/v1

DESCRIPTION:

FIELDS:
apiVersion
kind
metadata
annotations
clusterName
creationTimestamp
deletionGracePeriodSeconds
deletionTimestamp
finalizers <[]string>
generateName
generation
initializers
pending <[]Object>
name
result
apiVersion
code
details
causes <[]Object>
field
message
reason
group
kind
name
retryAfterSeconds
uid
kind
message
metadata
continue
resourceVersion
selfLink
reason
status
labels
managedFields <[]Object>
apiVersion
fields
manager
operation
time
name
namespace
ownerReferences <[]Object>
apiVersion
blockOwnerDeletion
controller
kind
name
uid
resourceVersion
selfLink
uid
spec <>
```

## Test Case #3
CRD with openAPI plus spec.type = object. It's a small change from #2 but as you will see it makes a huge difference.
```yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
version: v1
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
validation:
openAPIV3Schema:
properties:
spec:
type: object
properties:
cronSpec:
type: string
pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
replicas:
type: integer
minimum: 1
maximum: 10
```
```sh
>sh -x test.sh crontab-crd-object-spec.yaml
+ kubectl delete crontabs --all --ignore-not-found=true
No resources found
+ kubectl delete crd crontabs.stable.example.com --ignore-not-found=true
customresourcedefinition.apiextensions.k8s.io "crontabs.stable.example.com" deleted
+ kubectl apply -f crontab-crd-object-spec.yaml
customresourcedefinition.apiextensions.k8s.io/crontabs.stable.example.com created
+ sleep 3
+ kubectl explain crontab --recursive
KIND: CronTab
VERSION: stable.example.com/v1

DESCRIPTION:

FIELDS:
apiVersion
kind
metadata
annotations
clusterName
creationTimestamp
deletionGracePeriodSeconds
deletionTimestamp
finalizers <[]string>
generateName
generation
initializers
pending <[]Object>
name
result
apiVersion
code
details
causes <[]Object>
field
message
reason
group
kind
name
retryAfterSeconds
uid
kind
message
metadata
continue
resourceVersion
selfLink
reason
status
labels
managedFields <[]Object>
apiVersion
fields
manager
operation
time
name
namespace
ownerReferences <[]Object>
apiVersion
blockOwnerDeletion
controller
kind
name
uid
resourceVersion
selfLink
uid
spec
cronSpec
replicas
```