Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mingfang/kubernetes-crd-test
- Owner: mingfang
- Created: 2019-03-27T15:23:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-03-27T17:12:31.000Z (over 5 years ago)
- Last Synced: 2024-11-06T15:18:24.654Z (about 2 months ago)
- Language: Shell
- Size: 8.79 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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/v1DESCRIPTION:
```## 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/v1DESCRIPTION:
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/v1DESCRIPTION:
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
```