Skip to content

Commit 5b7c674

Browse files
authored
Merge pull request #41136 from adellape/hybrid_helm_410
2 parents c01dd91 + dbd7233 commit 5b7c674

16 files changed

+752
-2
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,8 @@ Topics:
14481448
File: osdk-helm-project-layout
14491449
- Name: Helm support
14501450
File: osdk-helm-support
1451+
- Name: Hybrid Helm Operator
1452+
File: osdk-hybrid-helm
14511453
- Name: Defining cluster service versions (CSVs)
14521454
File: osdk-generating-csvs
14531455
- Name: Working with bundle images

cli_reference/osdk/cli-osdk-install.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See xref:../../operators/operator_sdk/osdk-about.adoc#osdk-about[Developing Oper
1414

1515
[NOTE]
1616
====
17-
{product-title} 4.9 and later supports Operator SDK v1.10.1.
17+
{product-title} 4.9 and later supports Operator SDK v1.16.0.
1818
====
1919

2020
include::modules/osdk-installing-cli-linux-macos.adoc[leveloffset=+1]

modules/osdk-common-prereqs.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// * operators/operator_sdk/ansible/osdk-ansible-tutorial.adoc
77
// * operators/operator_sdk/helm/osdk-helm-quickstart.adoc
88
// * operators/operator_sdk/helm/osdk-helm-tutorial.adoc
9+
// * operators/operator_sdk/helm/osdk-hybrid-helm.adoc
910
// * operators/operator_sdk/osdk-working-bundle-images.adoc
1011

1112
ifeval::["{context}" == "osdk-ansible-quickstart"]
@@ -31,7 +32,7 @@ ifdef::ansible[]
3132
- link:https://pypi.org/project/openshift/[OpenShift Python client] version v0.12.0+
3233
endif::[]
3334
- Logged into an {product-title} {product-version} cluster with `oc` with an account that has `cluster-admin` permissions
34-
- To allow the cluster pull the image, the repository where you push your image must be set as public, or you must configure an image pull secret
35+
- To allow the cluster to pull the image, the repository where you push your image must be set as public, or you must configure an image pull secret
3536

3637
ifeval::["{context}" == "osdk-ansible-quickstart"]
3738
:!ansible:

modules/osdk-hh-create-cr.adoc

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
----

modules/osdk-hh-create-go-api.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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-go-api_{context}"]
7+
= Creating a Go API
8+
9+
Use the Operator SDK CLI to create a Go API.
10+
11+
.Procedure
12+
13+
. Run the following command to create a Go API with group `cache`, version `v1`, and kind `MemcachedBackup`:
14+
+
15+
[source,terminal]
16+
----
17+
$ operator-sdk create api \
18+
--group=cache \
19+
--version v1 \
20+
--kind MemcachedBackup \
21+
--resource \
22+
--controller \
23+
--plugins=go/v3
24+
----
25+
26+
. When prompted, enter `y` for creating both resource and controller:
27+
+
28+
[source,terminal]
29+
----
30+
$ Create Resource [y/n]
31+
y
32+
Create Controller [y/n]
33+
y
34+
----
35+
36+
This procedure generates the `MemcachedBackup` resource API at `api/v1/memcachedbackup_types.go` and the controller at `controllers/memcachedbackup_controller.go`.

modules/osdk-hh-create-helm-api.adoc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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-helm-api_{context}"]
7+
= Creating a Helm API
8+
9+
Use the Operator SDK CLI to create a Helm API.
10+
11+
.Procedure
12+
13+
* Run the following command to create a Helm API with group `cache`, version `v1`, and kind `Memcached`:
14+
+
15+
[source,terminal]
16+
----
17+
$ operator-sdk create api \
18+
--plugins helm.sdk.operatorframework.io/v1 \
19+
--group cache \
20+
--version v1 \
21+
--kind Memcached
22+
----
23+
24+
[NOTE]
25+
====
26+
This procedure also configures your Operator project to watch the `Memcached` resource with API version `v1` and scaffolds a boilerplate Helm chart. Instead of creating the project from the boilerplate Helm chart scaffolded by the Operator SDK, you can alternatively use an existing chart from your local file system or remote chart repository.
27+
28+
For more details and examples for creating Helm API based on existing or new charts, run the following command:
29+
30+
[source,terminal]
31+
----
32+
$ operator-sdk create api --plugins helm.sdk.operatorframework.io/v1 --help
33+
----
34+
====

modules/osdk-hh-create-project.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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-project_{context}"]
7+
= Creating a project
8+
9+
Use the Operator SDK CLI to create a project called `memcached-operator`.
10+
11+
.Procedure
12+
13+
. Create a directory for the project:
14+
+
15+
[source,terminal]
16+
----
17+
$ mkdir -p $HOME/github.com/example/memcached-operator
18+
----
19+
20+
. Change to the directory:
21+
+
22+
[source,terminal]
23+
----
24+
$ cd $HOME/github.com/example/memcached-operator
25+
----
26+
27+
. Run the `operator-sdk init` command to initialize the project. Use a domain of `example.com` so that all API groups are `<group>.example.com`:
28+
+
29+
[source,terminal]
30+
----
31+
$ operator-sdk init \
32+
--plugins=hybrid.helm.sdk.operatorframework.io \
33+
--project-version="3" \
34+
--domain example.com \
35+
--repo=github.com/example/memcached-operator
36+
----
37+
+
38+
The `init` command generates the RBAC rules in the `config/rbac/role.yaml` file based on the resources that would be deployed by the chart's default manifests. Verify that the rules generated in the `config/rbac/role.yaml` file meet your Operator's permission requirements.

modules/osdk-hh-defining-go-api.adoc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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-defining-go-api_{context}"]
7+
= Defining the API
8+
9+
Define the API for the `MemcachedBackup` custom resource (CR).
10+
11+
Represent this Go API by defining the `MemcachedBackup` type, which will have a `MemcachedBackupSpec.Size` field to set the quantity of Memcached backup instances (CRs) to be deployed, and a `MemcachedBackupStatus.Nodes` field to store a CR's pod names.
12+
13+
[NOTE]
14+
====
15+
The `Node` field is used to illustrate an example of a `Status` field.
16+
====
17+
18+
.Procedure
19+
20+
. Define the API for the `MemcachedBackup` CR by modifying the Go type definitions in the `api/v1/memcachedbackup_types.go` file to have the following `spec` and `status`:
21+
+
22+
.Example `api/v1/memcachedbackup_types.go` file
23+
[%collapsible]
24+
====
25+
[source,golang]
26+
----
27+
// MemcachedBackupSpec defines the desired state of MemcachedBackup
28+
type MemcachedBackupSpec struct {
29+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
30+
// Important: Run "make" to regenerate code after modifying this file
31+
32+
//+kubebuilder:validation:Minimum=0
33+
// Size is the size of the memcached deployment
34+
Size int32 `json:"size"`
35+
}
36+
37+
// MemcachedBackupStatus defines the observed state of MemcachedBackup
38+
type MemcachedBackupStatus struct {
39+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
40+
// Important: Run "make" to regenerate code after modifying this file
41+
// Nodes are the names of the memcached pods
42+
Nodes []string `json:"nodes"`
43+
}
44+
----
45+
====
46+
47+
. Update the generated code for the resource type:
48+
+
49+
[source,terminal]
50+
----
51+
$ make generate
52+
----
53+
+
54+
[TIP]
55+
====
56+
After you modify a `*_types.go` file, you must run the `make generate` command to update the generated code for that resource type.
57+
====
58+
59+
. After the API is defined with `spec` and `status` fields and CRD validation markers, generate and update the CRD manifests:
60+
+
61+
[source,terminal]
62+
----
63+
$ make manifests
64+
----
65+
66+
This Makefile target invokes the `controller-gen` utility to generate the CRD manifests in the `config/crd/bases/cache.my.domain_memcachedbackups.yaml` file.

modules/osdk-hh-helm-api-logic.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * operators/operator_sdk/helm/osdk-hybrid-helm.adoc
4+
5+
:_content-type: CONCEPT
6+
[id="osdk-hh-helm-api-logic_{context}"]
7+
= Operator logic for the Helm API
8+
9+
By default, your scaffolded Operator project watches `Memcached` resource events as shown in the `watches.yaml` file and executes Helm releases using the specified chart.
10+
11+
.Example `watches.yaml` file
12+
[%collapsible]
13+
====
14+
[source,yaml]
15+
----
16+
# Use the 'create api' subcommand to add watches to this file.
17+
- group: cache.my.domain
18+
version: v1
19+
kind: Memcached
20+
chart: helm-charts/memcached
21+
#+kubebuilder:scaffold:watch
22+
----
23+
====

0 commit comments

Comments
 (0)