cnpg-i-hello-world

command module
v0.0.0-...-1558157 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

CNPG-I Hello World Plugin

A CNPG-I plugin to add user-defined labels, annotations and a specific pause sidecar to the pods of CloudNativePG clusters.

This project serves as an introductory guide to bootstrapping a CNPG-I plugin and leveraging lifecycle hooks within a development environment. While similar results can be achieved through simpler methods such as mutating webhooks or CNPG's built-in features, this project is specifically designed to familiarize developers with the plugin workflow. By understanding how lifecycle hooks interact with other interfaces, developers can gain a deeper insight into implementing complex resource changes in real-world applications.

This plugin uses the pluginhelper from cnpg-i-machinery to simplify the plugin's implementation.

Running the plugin

To see the plugin in execution, you need to have a Kubernetes cluster running (we'll use Kind) and the CloudNativePG operator installed. The plugin also requires certificates to communicate with the operator, hence we are also installing cert-manager to manage them.

kind create cluster --name cnpg-i-hello-world
# Choose the latest version of CloudNativePG (at least 1.24)
kubectl apply --server-side -f \
  https://github.com/cloudnative-pg/cloudnative-pg/releases/download/vX.Y.Z/cnpg-X.Y.Z.yaml
# Choose the latest version of cert-manager
kubectl apply -f \
  https://github.com/cert-manager/cert-manager/releases/download/vX.Y.Z/cert-manager.yaml

Then install the plugin by applying the manifest:

kubectl apply -f https://github.com/cloudnative-pg/cnpg-i-hello-world/releases/download/v0.1.0/manifest.yaml

Finally, create a cluster resource to see the plugin in action. There are three examples in the doc/examples directory:

  1. Cluster with labels and annotations: adds the defined labels and annotations to the pods. Showcases the plugin capability of altering the lifecycle of the CloudNativePG resources.
  2. Cluster with no parameters: defaults the plugin settings of the cluster. Showcases the plugin capability of altering the defaulting webhook behavior.
  3. Cluster with wrong parameters: includes an error in the configuration. Showcases the plugin capability of validating its own configuration.

Plugin development

For additional details on the plugin implementation refer to the development documentation.

Documentation

Overview

Package main is the entrypoint of the application

Directories

Path Synopsis
cmd
plugin
Package plugin implements the command to start the plugin
Package plugin implements the command to start the plugin
internal
config
Package config represents the plugin configuration
Package config represents the plugin configuration
identity
Package identity contains the implementation of the identity service
Package identity contains the implementation of the identity service
k8sclient
Package k8sclient ensure a Kubernetes client is available
Package k8sclient ensure a Kubernetes client is available
lifecycle
Package lifecycle implements the lifecycle hooks
Package lifecycle implements the lifecycle hooks
operator
Package operator contains the implementation of the operator service
Package operator contains the implementation of the operator service
utils
Package utils contains methods to interact with kubernetes resources
Package utils contains methods to interact with kubernetes resources
pkg
metadata
Package metadata contains the metadata of this plugin
Package metadata contains the metadata of this plugin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL