Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown linting, fix link fragment, and update writeEvent function #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions site/content/en/main/pepr-tutorials/create-pepr-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ This tutorial will walk you through the process of building a Kubernetes Operato

## Background


The WebApp Operator deploys the WebApp `CustomResourceDefinition`, then watches and reconciles against instances of WebApps to ensure the desired state meets the actual cluster state.

The WebApp instance represents a `Deployment` object with configurable replicas, a `Service`, and a `ConfigMap` that has a `index.html` file that can be configured to a specific language, and theme. The resources the Operator deploys contain `ownerReferences`, causing a cascading delete effect when the WebApp instance is deleted.

If any object deployed by the Operator is deleted for any reason, the Operator will abruptly redeploy the object.
If any object deployed by the Operator is deleted for any reason, the Operator will abruptly redeploy the object.

## Steps

- [Create a new Pepr Module](#create-a-new-pepr-module)
- [Create CRD](#create-crd)
- [Create Helpers](#create-helpers)
- [Create Reconciler](#create-reconciler)
- [Build and Deploy](#build-and-deploy)
- [Create Reconciler](#create-reconciler)
- [Demo](#demo)

## Create a new Pepr Module

```bash
Expand Down Expand Up @@ -681,7 +680,7 @@ export async function reconciler(instance: WebApp) {
* @param status The new status
*/
async function updateStatus(instance: WebApp, status: Status) {
await writeEvent(instance, {phase: status}, "Normal", "CreatedOrUpdate", instance.metadata.name, instance.metadata.name);
await writeEvent(instance, {message: status.phase}, "Normal", "CreatedOrUpdate", instance.metadata.name, instance.metadata.name);
await K8s(WebApp).PatchStatus({
metadata: {
name: instance.metadata!.name,
Expand Down Expand Up @@ -772,6 +771,7 @@ When(a.ConfigMap)
});

```

- When a WebApp is created or updated, validate it, store the name of the instance and enqueue it for processing.
- If an "owned" resource (ConfigMap, Service, or Deployment) is deleted, redeploy it.
- Always redeploy the WebApp CRD if it was deleted as the controller depends on it
Expand Down Expand Up @@ -801,7 +801,7 @@ Build the Pepr manifests (Already built with appropriate RBAC)
npx pepr build
```

Deploy the Operator
Deploy the Operator

```bash
kubectl apply -f dist/pepr-module-774fab07-77fa-517c-b5f8-c682c96c20c0.yaml
Expand Down Expand Up @@ -916,6 +916,7 @@ Port-forward and look at the WebApp in the browser
```bash
kubectl port-forward svc/webapp-light-en -n webapps 3000:80
```

[WebApp](http://localhost:3000)
![WebApp](light.png)

Expand Down Expand Up @@ -957,6 +958,7 @@ Port-forward and look at the WebApp in the browser
```bash
kubectl port-forward svc/webapp-light-en -n webapps 3000:80
```

[WebApp](http://localhost:3000)

![WebApp](dark.png)
Expand All @@ -974,7 +976,6 @@ configmap/kube-root-ca.crt 1 40s

When the WebApp is deleted, all of the resources that it created are also deleted.


## Conclusion

In this tutorial we created a Kubernetes Operator using Pepr. We created a CRD, created helper functions to help with the reconciliation process, and created a queue and reconciler to reconcile the state of the instance with the cluster. We also built and deployed the Operator and created an instance of the WebApp resource and watched the Operator reconcile the state of the instance with the cluster. Finally, we updated and deleted the instance and watched the Operator reconcile the manifests based in the updated instance and delete the resources when the instance was deleted.
Expand Down
17 changes: 9 additions & 8 deletions site/content/en/v0.42.0/pepr-tutorials/create-pepr-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ This tutorial will walk you through the process of building a Kubernetes Operato

## Background


The WebApp Operator deploys the WebApp `CustomResourceDefinition`, then watches and reconciles against instances of WebApps to ensure the desired state meets the actual cluster state.

The WebApp instance represents a `Deployment` object with configurable replicas, a `Service`, and a `ConfigMap` that has a `index.html` file that can be configured to a specific language, and theme. The resources the Operator deploys contain `ownerReferences`, causing a cascading delete effect when the WebApp instance is deleted.

If any object deployed by the Operator is deleted for any reason, the Operator will abruptly redeploy the object.
If any object deployed by the Operator is deleted for any reason, the Operator will abruptly redeploy the object.

## Steps

- [Create a new Pepr Module](#create-a-new-pepr-module)
- [Create CRD](#create-crd)
- [Create Helpers](#create-helpers)
- [Create Reconciler](#create-reconciler)
- [Build and Deploy](#build-and-deploy)
- [Create Reconciler](#create-reconciler)
- [Demo](#demo)

## Create a new Pepr Module

```bash
Expand Down Expand Up @@ -681,7 +680,7 @@ export async function reconciler(instance: WebApp) {
* @param status The new status
*/
async function updateStatus(instance: WebApp, status: Status) {
await writeEvent(instance, {phase: status}, "Normal", "CreatedOrUpdate", instance.metadata.name, instance.metadata.name);
await writeEvent(instance, {message: status.phase}, "Normal", "CreatedOrUpdate", instance.metadata.name, instance.metadata.name);
await K8s(WebApp).PatchStatus({
metadata: {
name: instance.metadata!.name,
Expand Down Expand Up @@ -772,6 +771,7 @@ When(a.ConfigMap)
});

```

- When a WebApp is created or updated, validate it, store the name of the instance and enqueue it for processing.
- If an "owned" resource (ConfigMap, Service, or Deployment) is deleted, redeploy it.
- Always redeploy the WebApp CRD if it was deleted as the controller depends on it
Expand Down Expand Up @@ -801,7 +801,7 @@ Build the Pepr manifests (Already built with appropriate RBAC)
npx pepr build
```

Deploy the Operator
Deploy the Operator

```bash
kubectl apply -f dist/pepr-module-774fab07-77fa-517c-b5f8-c682c96c20c0.yaml
Expand Down Expand Up @@ -916,6 +916,7 @@ Port-forward and look at the WebApp in the browser
```bash
kubectl port-forward svc/webapp-light-en -n webapps 3000:80
```

[WebApp](http://localhost:3000)
![WebApp](light.png)

Expand Down Expand Up @@ -957,6 +958,7 @@ Port-forward and look at the WebApp in the browser
```bash
kubectl port-forward svc/webapp-light-en -n webapps 3000:80
```

[WebApp](http://localhost:3000)

![WebApp](dark.png)
Expand All @@ -974,7 +976,6 @@ configmap/kube-root-ca.crt 1 40s

When the WebApp is deleted, all of the resources that it created are also deleted.


## Conclusion

In this tutorial we created a Kubernetes Operator using Pepr. We created a CRD, created helper functions to help with the reconciliation process, and created a queue and reconciler to reconcile the state of the instance with the cluster. We also built and deployed the Operator and created an instance of the WebApp resource and watched the Operator reconcile the state of the instance with the cluster. Finally, we updated and deleted the instance and watched the Operator reconcile the manifests based in the updated instance and delete the resources when the instance was deleted.
Expand Down