|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * operators/operator_sdk/helm/osdk-hybrid-helm.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="osdk-hh-create-cr_{context}"] |
| 7 | += Creating custom resources |
| 8 | + |
| 9 | +After your Operator is installed, you can test it by creating custom resources (CRs) that are now provided on the cluster by the Operator. |
| 10 | + |
| 11 | +.Procedure |
| 12 | + |
| 13 | +. Change to the namespace where your Operator is installed: |
| 14 | ++ |
| 15 | +[source,terminal] |
| 16 | +---- |
| 17 | +$ oc project <project_name>-system |
| 18 | +---- |
| 19 | + |
| 20 | +. Update the sample `Memcached` CR manifest at the `config/samples/cache_v1_memcached.yaml` file by updating the `replicaCount` field to `3`: |
| 21 | ++ |
| 22 | +.Example `config/samples/cache_v1_memcached.yaml` file |
| 23 | +[%collapsible] |
| 24 | +==== |
| 25 | +[source,yaml] |
| 26 | +---- |
| 27 | +apiVersion: cache.my.domain/v1 |
| 28 | +kind: Memcached |
| 29 | +metadata: |
| 30 | + name: memcached-sample |
| 31 | +spec: |
| 32 | + # Default values copied from <project_dir>/helm-charts/memcached/values.yaml |
| 33 | + affinity: {} |
| 34 | + autoscaling: |
| 35 | + enabled: false |
| 36 | + maxReplicas: 100 |
| 37 | + minReplicas: 1 |
| 38 | + targetCPUUtilizationPercentage: 80 |
| 39 | + fullnameOverride: "" |
| 40 | + image: |
| 41 | + pullPolicy: IfNotPresent |
| 42 | + repository: nginx |
| 43 | + tag: "" |
| 44 | + imagePullSecrets: [] |
| 45 | + ingress: |
| 46 | + annotations: {} |
| 47 | + className: "" |
| 48 | + enabled: false |
| 49 | + hosts: |
| 50 | + - host: chart-example.local |
| 51 | + paths: |
| 52 | + - path: / |
| 53 | + pathType: ImplementationSpecific |
| 54 | + tls: [] |
| 55 | + nameOverride: "" |
| 56 | + nodeSelector: {} |
| 57 | + podAnnotations: {} |
| 58 | + podSecurityContext: {} |
| 59 | + replicaCount: 3 |
| 60 | + resources: {} |
| 61 | + securityContext: {} |
| 62 | + service: |
| 63 | + port: 80 |
| 64 | + type: ClusterIP |
| 65 | + serviceAccount: |
| 66 | + annotations: {} |
| 67 | + create: true |
| 68 | + name: "" |
| 69 | + tolerations: [] |
| 70 | +---- |
| 71 | +==== |
| 72 | +
|
| 73 | +. Create the `Memcached` CR: |
| 74 | ++ |
| 75 | +[source,terminal] |
| 76 | +---- |
| 77 | +$ oc apply -f config/samples/cache_v1_memcached.yaml |
| 78 | +---- |
| 79 | +
|
| 80 | +. Ensure that the Memcached Operator creates the deployment for the sample CR with the correct size: |
| 81 | ++ |
| 82 | +[source,terminal] |
| 83 | +---- |
| 84 | +$ oc get pods |
| 85 | +---- |
| 86 | ++ |
| 87 | +.Example output |
| 88 | +[source,terminal] |
| 89 | +---- |
| 90 | +NAME READY STATUS RESTARTS AGE |
| 91 | +memcached-sample-6fd7c98d8-7dqdr 1/1 Running 0 18m |
| 92 | +memcached-sample-6fd7c98d8-g5k7v 1/1 Running 0 18m |
| 93 | +memcached-sample-6fd7c98d8-m7vn7 1/1 Running 0 18m |
| 94 | +---- |
| 95 | +
|
| 96 | +. Update the sample `MemcachedBackup` CR manifest at the `config/samples/cache_v1_memcachedbackup.yaml` file by updating the `size` to `2`: |
| 97 | ++ |
| 98 | +.Example `config/samples/cache_v1_memcachedbackup.yaml` file |
| 99 | +[%collapsible] |
| 100 | +==== |
| 101 | +[source,yaml] |
| 102 | +---- |
| 103 | +apiVersion: cache.my.domain/v1 |
| 104 | +kind: MemcachedBackup |
| 105 | +metadata: |
| 106 | + name: memcachedbackup-sample |
| 107 | +spec: |
| 108 | + size: 2 |
| 109 | +---- |
| 110 | +==== |
| 111 | +
|
| 112 | +. Create the `MemcachedBackup` CR: |
| 113 | ++ |
| 114 | +[source,terminal] |
| 115 | +---- |
| 116 | +$ oc apply -f config/samples/cache_v1_memcachedbackup.yaml |
| 117 | +---- |
| 118 | +
|
| 119 | +. Ensure that the count of `memcachedbackup` pods is the same as specified in the CR: |
| 120 | ++ |
| 121 | +[source,terminal] |
| 122 | +---- |
| 123 | +$ oc get pods |
| 124 | +---- |
| 125 | ++ |
| 126 | +.Example output |
| 127 | +[source,terminal] |
| 128 | +---- |
| 129 | +NAME READY STATUS RESTARTS AGE |
| 130 | +memcachedbackup-sample-8649699989-4bbzg 1/1 Running 0 22m |
| 131 | +memcachedbackup-sample-8649699989-mq6mx 1/1 Running 0 22m |
| 132 | +---- |
| 133 | +
|
| 134 | +. You can update the `spec` in each of the above CRs, and then apply them again. The controller reconciles again and ensures that the size of the pods is as specified in the `spec` of the respective CRs. |
| 135 | +
|
| 136 | +. Clean up the resources that have been created as part of this tutorial: |
| 137 | +
|
| 138 | +.. Delete the `Memcached` resource: |
| 139 | ++ |
| 140 | +[source,terminal] |
| 141 | +---- |
| 142 | +$ oc delete -f config/samples/cache_v1_memcached.yaml |
| 143 | +---- |
| 144 | +
|
| 145 | +.. Delete the `MemcachedBackup` resource: |
| 146 | ++ |
| 147 | +[source,terminal] |
| 148 | +---- |
| 149 | +$ oc delete -f config/samples/cache_v1_memcachedbackup.yaml |
| 150 | +---- |
| 151 | +
|
| 152 | +.. If you used the `make deploy` command to test the Operator, run the following command: |
| 153 | ++ |
| 154 | +[source,terminal] |
| 155 | +---- |
| 156 | +$ make undeploy |
| 157 | +---- |
0 commit comments