etoperator

command module
v0.0.0-...-37f37af Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

README

Electric Trees Operator

Overview

A simple operator with a CRD to create an "electric trees" resource.

TODO: Write some unit tests for the operator! The SDK seems to make the operator code eminently testable (defined input/output, injected client)

Quickstart

  • Run cd etoperator to get into this directory
  • Run make install to install the CRD manifest
  • Run make deploy NOTE: I don't think this step is actually needed
  • Run make run this starts the operator locally

In a separate terminal run

kustomize build config/samples | kubectl apply -f -

This will create the CRD instance and this should result in deployment and service being created, run kubectl get all to check, e.g.

kubectl get all                                     
NAME                                          READY   STATUS    RESTARTS   AGE
pod/electrictrees-mimi-app-67c4d579c7-7h7z4   1/1     Running   0          13m

NAME                             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/electrictrees-mimi-svc   NodePort    10.104.29.109   <none>        7777:32707/TCP   13m
service/kubernetes               ClusterIP   10.96.0.1       <none>        443/TCP          11h

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/electrictrees-mimi-app   1/1     1            1           13m

NAME                                                DESIRED   CURRENT   READY   AGE
replicaset.apps/electrictrees-mimi-app-67c4d579c7   1         1         1       13m

Environment

Most of this work was carried out on an M1 Mac with Docker Desktop, zsh, and homebrew for installing tools. A few crucial points

  • I have homebrew installed in untar anywhere mode because I don't like tools having admin permissions or even needing them to install
  • I use direnv to setup environment for this project
  • The GOPATH is set to <repo>/.gopath in a .envrc file that direnv picks up you need to direnv allow . at the root of the cloned repo for this to work

Setup

These are the steps I used to create and setup this project, you don't need to follow them to simply run/use the code.

Install pre-requisites
MacOS
brew install direnv
brew install kustomize
Install Operator SDK
MacOS
brew install operator-sdk
Build From Go
cd ~/wd/3rdparty

git clone https://github.com/operator-framework/operator-sdk
cd operator-sdk
git checkout master

# Ensure the install location is in the path 
make install
Initialise

Ran these commands

cd etoperator

operator-sdk init --domain hiklas.com --owner "Fiona Bianchi" --repo github.com/fionahiklas/simple-kubernetes-crd/etoperator

NOTE: If you have any backup files, for example README.md~ the init command will complain

Error: failed to initialize project: unable to run pre-scaffold tasks of "base.go.kubebuilder.io/v3": target directory is not empty (only go.mod, go.sum, files and directories with the prefix ".", files with the suffix ".md" or capitalized files name are allowed); found existing file "README.md~"

Also I got this warning

WARN[0000] the platform of this environment (darwin/arm64) is not suppported by kustomize v3 (v3.8.7) which is used in this scaffold. You will be unable to download a binary for the kustomize version supported and used by this plugin. The currently supported platforms are: ["linux/amd64" "linux/arm64" "darwin/amd64"] 

This is fixed by adding the kustomize prerequisite

Creating API

Running this command

operator-sdk create api --version=v1alpha1 --kind=ElectricTrees

Creating the manifests

make manifests
Coding

Following the Redhat operator tutorial for guidance on commands and code to creating a service and deployment from the ElectricTrees Custom Resource Definition

References

Operator SDK

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1alpha1
Package v1alpha1 contains API Schema definitions for the v1alpha1 API group +kubebuilder:object:generate=true +groupName=hiklas.com
Package v1alpha1 contains API Schema definitions for the v1alpha1 API group +kubebuilder:object:generate=true +groupName=hiklas.com

Jump to

Keyboard shortcuts

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