Skip to content

astrokube/kubebuilder-initializer-plugin

Repository files navigation

GitHub Release Go Reference go.mod License Build Status CodeQL

Kubebuilder Initializer Plugin

A powerful Kubebuilder plugin to initialize dynamically the structure of your kubebuilder operator repositories.

Prerequisites

This is a plugin for the kubebuilder tool. In case of you haven't installed the tool yet, please visit the kubebuilder documentation and follow the instructions to get kuberbuilder properly installed in your computer.

Installation

Homebrew

  1. Add the Astrokube repo
brew tap astrokube/tools
  1. Install Kubebyuilder Initializer plugin:
brew install kubebuilder-initializer-plugin
  1. Please, create a symbolic link (this is required as the Kubebuilder cli will look at that folder to load the external plugins)
mkdir -p ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer-plugin/v1-alpha/
ln -s /usr/local/Cellar/kubebuilder-initializer-plugin/0.1.0/bin/kubebuilder-initializer-plugin \
  ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer-plugin/v1-alpha/kubebuilder-initializer-plugin

Download the executable files

  1. Visit the latest release at Release page
  2. Download the version that works for you
  3. Extract the files in the tarball that you downloaded in the previous step
  4. Copy the executable file to the path used by Kubebuilder to read the external plugins
    • OSX: ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer/v1-alpha
    • Linux: $HOME/.config/kubebuilder/plugins/kubebuilder-initializer/v1-alpha

Build from the code

git clone https://github.com/astrokube/kubebuilder-initializer-plugin.git
cd kubebuilder-initializer-plugin
make build install

To check that installation was success, please check that the executable file was copied to the folder used by Kubebuilder to read the plugins

  • OSX: ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer/v1-alpha
  • Linux: $HOME/.config/kubebuilder/plugins/kubebuilder-initializer/v1-alpha

Getting started

To deep dive into how Kubebuilder deals with external plugins you can visit the following article Extensible CLI and Scaffolding Plugins - Phase 2

Once you have installed the plugin you can use the Kubebuilder cli as usual.

  1. Check that the plugin has been installed correctly
kubebuilder help

And the kubebuilder-initializer-plugin/v1-alpha is displayed as part of the list of available plugins.

Kubebuilder pLugins

  1. Choose the template for scaffolding the initial structure of our Kubebuilder operator. You can create your own template as described (here]() or alternatively you could take advantage of some of the well-known templates that you can find in AWESOME_TEMPLATES.md

  2. Once we have chosen the template that we want to use, we just need to write the yaml file that contains the values that will make us to customize the template. By default, the plugin will take a file named .kubebuilder-layout.yaml, otherwise you will need to pass an extra argument with the path to the file.

  3. Initialize your project. Keep in mind that this plugin is used exclusively to initialize our project structure, so we should use also a plugin that supports the APIs and webhooks creation,for instance the go.kubebuilder.io/v3 that is prpvided out

main of the box by Kubbebuilder.

kubebuilder init  --plugins go.kubebuilder.io/v3,kubebuilder-layout/v1-alpha \
  --from "github.com/astrokube/kubebuilder-operator-template" \
  --domain astrokube \
  --owner astrokube \
  --repo github.com/astrokube/k8s-testing-operator

The only argument that needs to be passed is the from

In the above example, the args domain, repo and owner are required by the plugin go.kubebuilder.io/v3.

Non default branches

By default, the plugin will fetch the code in the default branch, buy we can specify a branch:

--from "github.com/astrokube/kubebuilder-operator-template#<branch>"

With credentials

For those repositories that require authentication we can provide the user credentials or a token as It's shown on the below

--from "<user>:<password>@github.com/astrokube/kubebuilder-operator-template"
...
 --from "<token>@github.com/astrokube/kubebuilder-operator-template"

Contributing

Visit the CONTRIBUTING.md file.

About

A powerful Kubebuilder plugin to initialize dynamically the structure of your operator repositories.

Topics

Resources

License

Stars

Watchers

Forks