Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit e5249df

Browse files
committed
build: step4
issue #4
1 parent f44927e commit e5249df

File tree

8 files changed

+366
-19
lines changed

8 files changed

+366
-19
lines changed

.doc/5-tutorial.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ make deploy IMG=kind-registry:5000/library/controller:latest
142142
```
143143

144144
```shell
145-
kubectl -n custom-kubernetes-controller-system get deployment
146-
kubectl -n custom-kubernetes-controller-system describe deployment/custom-kubernetes-controller-controller-manager
145+
kubectl -n custom-kubernetes-controller-system get deployments
146+
kubectl -n custom-kubernetes-controller-system describe deployments custom-kubernetes-controller-controller-manager
147147
kubectl -n custom-kubernetes-controller-system describe pod custom-kubernetes-controller-controller-manager
148-
kubectl -n custom-kubernetes-controller-system logs deployment/custom-kubernetes-controller-controller-manager
148+
kubectl -n custom-kubernetes-controller-system logs deployments custom-kubernetes-controller-controller-manager
149+
kubectl -n custom-kubernetes-controller-system logs pods/custom-kubernetes-controller-controller-manager-...
149150

150151
kubectl get pods --all-namespaces
151152
kubectl get deployments --all-namespaces

.doc/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
## Localy
1212

1313
```shell
14+
export NGINX_IMAGE="nginx:1.25.3-alpine3.18-slim"
1415
make install run
1516

1617
kubectl apply -f config/samples/
@@ -20,6 +21,8 @@ make uninstall
2021

2122
## Docker
2223

24+
The script provided at [this link](https://kind.sigs.k8s.io/docs/user/local-registry/).
25+
2326
```shell
2427
./.script/kind-with-registry.sh
2528

@@ -48,3 +51,11 @@ kubectl apply -f config/samples/
4851

4952
operator-sdk cleanup custom-kubernetes-controller
5053
```
54+
55+
## Check the Pods
56+
57+
```shell
58+
kubectl get deployments
59+
kubectl logs deployments/dummy1
60+
kubectl describe deployments/dummy1
61+
```

api/v1alpha1/dummy_types.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ type DummySpec struct {
2828
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2929
// Important: Run "make" to regenerate code after modifying this file
3030

31-
// Message is an example field of Dummy.
31+
// Message is a field of Dummy Spec.
32+
// +kubebuilder:default:="I'm just a dummy"
3233
// +operator-sdk:csv:customresourcedefinitions:type=spec
3334
Message string `json:"message,omitempty"`
3435
}
@@ -38,13 +39,20 @@ type DummyStatus struct {
3839
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
3940
// Important: Run "make" to regenerate code after modifying this file
4041

41-
// SpecEcho is an example field of Dummy Status.
42+
// SpecEcho is an field of Dummy Status.
43+
// +kubebuilder:default:="I'm just a dummy"
4244
// +operator-sdk:csv:customresourcedefinitions:type=status
4345
SpecEcho string `json:"specEcho,omitempty"`
46+
47+
// PodStatus is an field of Dummy Status.
48+
// +kubebuilder:default:="Pending"
49+
// +operator-sdk:csv:customresourcedefinitions:type=status
50+
PodStatus string `json:"podStatus,omitempty"`
4451
}
4552

4653
//+kubebuilder:object:root=true
4754
//+kubebuilder:subresource:status
55+
//+kubebuilder:resource:scope=Namespaced
4856

4957
// Dummy is the Schema for the dummies API
5058
type Dummy struct {
@@ -65,5 +73,13 @@ type DummyList struct {
6573
}
6674

6775
func init() {
68-
SchemeBuilder.Register(&Dummy{}, &DummyList{})
76+
SchemeBuilder.Register(&Dummy{
77+
Spec: DummySpec{
78+
Message: "I'm just a dummy",
79+
},
80+
Status: DummyStatus{
81+
SpecEcho: "I'm just a dummy",
82+
PodStatus: "Pending",
83+
},
84+
}, &DummyList{})
6985
}

cmd/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ func main() {
9292
if err = (&controller.DummyReconciler{
9393
Client: mgr.GetClient(),
9494
Scheme: mgr.GetScheme(),
95+
// Add a Recorder to the reconciler.
96+
// This allows the operator author to emit events during reconcilliation.
97+
Recorder: mgr.GetEventRecorderFor("dummy-controller"),
9598
}).SetupWithManager(mgr); err != nil {
9699
setupLog.Error(err, "unable to create controller", "controller", "Dummy")
97100
os.Exit(1)

config/crd/bases/interview.com_dummies.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ spec:
3535
description: DummySpec defines the desired state of Dummy
3636
properties:
3737
message:
38-
description: Message is an example field of Dummy.
38+
default: I'm just a dummy
39+
description: Message is a field of Dummy Spec.
3940
type: string
4041
type: object
4142
status:
4243
description: DummyStatus defines the observed state of Dummy
4344
properties:
45+
podStatus:
46+
default: Pending
47+
description: PodStatus is an field of Dummy Status.
48+
type: string
4449
specEcho:
45-
description: SpecEcho is an example field of Dummy Status.
50+
default: I'm just a dummy
51+
description: SpecEcho is an field of Dummy Status.
4652
type: string
4753
type: object
4854
type: object

config/manager/manager.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ spec:
7272
- --leader-elect
7373
image: controller:latest
7474
name: manager
75+
env:
76+
- name: NGINX_IMAGE
77+
value: nginx:1.25.3-alpine3.18-slim
7578
securityContext:
7679
allowPrivilegeEscalation: false
7780
capabilities:

config/samples/_v1alpha1_dummy.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apiVersion: interview.com/v1alpha1
22
kind: Dummy
33
metadata:
4-
# labels:
5-
# app.kubernetes.io/name: dummy
6-
# app.kubernetes.io/instance: dummy-sample
7-
# app.kubernetes.io/part-of: custom-kubernetes-controller
8-
# app.kubernetes.io/managed-by: kustomize
9-
# app.kubernetes.io/created-by: custom-kubernetes-controller
4+
labels:
5+
app.kubernetes.io/name: dummy
6+
app.kubernetes.io/instance: dummy-sample
7+
app.kubernetes.io/part-of: custom-kubernetes-controller
8+
app.kubernetes.io/managed-by: kustomize
9+
app.kubernetes.io/created-by: custom-kubernetes-controller
1010
name: dummy1
1111
namespace: default
1212
spec:

0 commit comments

Comments
 (0)