naml

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: Apache-2.0 Imports: 31 Imported by: 2

README

Go Reference

Not another markup language.

Replace Kubernetes YAML with raw Go!

Say so long 👋 to YAML and start using the Go 🎉 programming language to represent and deploy applications.

✅ Take advantage of all the lovely features of Go.

✅ Test your code directly in local Kubernetes using kind.

✅ Get your application directly into Go instead of YAML and use it in controllers, operators, CRs/CRDs easily. Use the Go compiler to your advantage.

Quickstart

Turn existing YAML into Go.

If you have existing YAML on disk or in a Kubernetes cluster, you can pipe it directly to naml codify to generate Go code.

mkdir out

# Get started quickly with all objects in a namespace
kubectl get all -n default -o yaml | naml codify > out/main.go

# Pipe multiple .yaml files to a single Application
cat deployment.yaml service.yaml | naml codify \
  --author-name="Charlie" \
  --author-email="<charlie@nivenly.com>" > out/main.go

Copy the generic Makefile to the same directory as your main.go

wget https://raw.githubusercontent.com/kris-nova/naml/main/out/Makefile -o out/Makefile

Use make help for more. Happy coding 🎉.

Examples

There is a "repository" of examples to borrow/fork:

  • examples GitHub organization.
  • simple quick and simple example.
  • full example pattern to simulate a Values.yaml file.

Usage

# Compile your code using the naml library
make

# Once an application is compiled with naml
# they can be standalone executables, or referenced from the default binary.
naml -f app.naml list

# Is the same as
./app.naml list

# install 
naml -f app.naml install App

# uninstall 
naml -f app.naml uninstall App
Implement Deployable

As long as there is a Go system that implements this interface it can be used with naml. See examples for how to include an implementation in your project.

// Deployable is used to deploy applications.
type Deployable interface {

	// Install will attempt to install in Kubernetes
	Install(client *kubernetes.Clientset) error

	// Uninstall will attempt to uninstall in Kubernetes
	Uninstall(client *kubernetes.Clientset) error

	// Meta returns the Kubernetes native ObjectMeta which is used to manage applications with naml.
	Meta() *v1.ObjectMeta
	
	// Description will return the description of the application.
	Description() string
}

About

This is a framework for infrastructure teams who need more than just conditional manifests.

This allows teams to start encapsulating, managing, and testing their applications in raw Go.

Teams can now buid controllers, operators, and custom toolchains using reliable, testable, and scalable Go.

The philosophy

The bet here is that any person confident in managing YAML for Kubernetes can also be equally as confident managing Go for Kubernetes.

The feature add is that no matter how good our YAML management tools get, they will never be as good as just plain Go when it comes to things like syntax checking, testing, shipping, and flexibility.

Nothing fancy

Feel free to fork this repository and begin using it for your team. There isn't anything special here. 🤷‍♀ We use the same client the rest of Kubernetes does.

❎ No new tools.

❎ No charts.

❎ No templating at runtime.

❎ No vague error messages.

❎ No more YAML guessing/checking.

✅ Just Go. 🎉

Features

✨ There is not a single .yaml file in this entire repository. ✨

  • Express applications in 🎉 Go instead of YAML.
  • Use the Go compiler to check your syntax.
  • Write real tests 🤓 using Go to check and validate your deployments.
  • Test your applications in Kubernetes using kind.
  • Define custom installation logic. What happens if it fails?
  • Define custom application registries. Multiple apps of the same flavor? No problem.
  • Use the latest client (the same client the rest of Kubernetes uses).

Documentation

Index

Constants

View Source
const (
	KubeconfigEnvironmentalVariable = "KUBECONFIG"
	KubeconfigDefaultDirectory      = ".kube"
	KubeconfigDefaultFile           = "config"
)
View Source
const FormatMainGo string = `` /* 2803-byte string literal not displayed */
View Source
const (
	// TestClusterName is used to identify the test cluster with Kind.
	TestClusterName string = "namltestcluster"
)
View Source
const YAMLDelimiter string = "---"

YAMLDelimiter is the official delimiter used to append multiple YAML files together into the same file.

Reference: https://yaml.org/spec/1.2/spec.html

Furthermore let it be documented that at the 2018 KubeCon pub trivia Bryan Liles (https://twitter.com/bryanl) correctly had answered the trivia question with the correct delimiter of 3 characters "---" and was awarded no points for his correct answer, while an opposing team was awarded a single point for their incorrect answer of 2 characters "--".

If the correct delimiter points would have been awarded to Brian's team they would technically should have been crowned KubeCon pub champions of 2018.

Variables

View Source
var Version string

Version is this specific version on naml

Functions

func AddRPC

func AddRPC(path string) error

AddRPC will attempt to add a remote RPC server to the current runtime.

func AllInit

func AllInit(kubeConfigPath string, verbose bool, with []string) error

AllInit is the "constructor" for every command line flag. This is how we use naml -w to include sub-namls

func Banner()

func BusyboxDeployment

func BusyboxDeployment(name string) *v1.Deployment

BusyboxDeployment is useful for quick testing and debugging. This is broken by design.

func Client

func Client() (*kubernetes.Clientset, error)

Client is used to authenticate with Kubernetes and build the Kube client for the rest of the program.

func ClientFromFlags

func ClientFromFlags(apiUrl, kubeConfigPath string) (*kubernetes.Clientset, error)

ClientFromFlags will plumb well-known command line flags through to the kubeconfig

func ClientFromPath

func ClientFromPath(kubeConfigPath string) (*kubernetes.Clientset, error)

ClientFromPath is used to authenticate with Kubernetes and build the Kube client for the rest of the program given a specific kube config path.

Useful for testing.

func Codify added in v0.2.6

func Codify(input io.Reader, v *MainGoValues) ([]byte, error)

Codify will take any valid Kubernetes YAML as an io.Reader and do it's best to return a syntactically correct Go program that is NAML compliant.

The NAML codebase is Apache 2.0 licensed, so we assume that any calling code will adopt the same Apache license.

func I32p

func I32p(i int32) *int32

func I64p

func I64p(i int64) *int64

func Install

func Install(app Deployable) error

Install is used to install an application in Kubernetes

func List

func List()

List the naml package information in stdout

func Register

func Register(app Deployable)

Register an application with naml

func RegisterAndError

func RegisterAndError(app Deployable) error

func RegisterAndExit

func RegisterAndExit(app Deployable)

RegisterAndExit will register the app or exit with an error message in stdout

func RegisterRemoteApplications

func RegisterRemoteApplications() error

RegisterRemoteApplications will call list() on all remote RPC servers and register the applications as pointers on the remote.

func Registry

func Registry() map[string]Deployable

Registry will return the registry

func RunCommandLine

func RunCommandLine() error

RunCommandLine is the global NAML command line program.

Use this if you would like to use the built in NAML command line interface.

func RunCommandLineAndExit

func RunCommandLineAndExit()

func RunCommandLineWithOptions

func RunCommandLineWithOptions() error

RunCommandLineWithOptions is here so we can default values in RunCommandLine() that we would want to pass in here later (tests, etc)

func RunRPC

func RunRPC() error

RunRPC will run in RPC mode.

TODO: Nóva to come add security auth and validation to our RPC

func Stringp

func Stringp(i string) *string

func TestClusterKubeConfigPath

func TestClusterKubeConfigPath() string

TestClusterKubeConfigPath will export the kubeconfig path to this directory to use for the client in the tests.

func TestClusterStart

func TestClusterStart() error

TestClusterStart can be used to start the test cluster in the TestMain() function.

func TestClusterStop

func TestClusterStop() error

TestClusterStop can be used to stop the test cluster in the TestMain() function.

func Uninstall

func Uninstall(app Deployable) error

Uninstall is used to uninstall an application in Kubernetes

Types

type CodifyObject added in v0.2.6

type CodifyObject interface {
	// Install returns the snippet of code that would
	// traditionall live INSIDE of a function. This
	// will define literally (what it can) a struct
	// for the object, and pass it to the corresponding
	// kubernetes library.
	Install() string

	// Uninstall is the reverse library call of install
	Uninstall() string
}

func YAMLToCodifyObjects added in v0.2.6

func YAMLToCodifyObjects(raw []byte) ([]CodifyObject, error)

type Deployable

type Deployable interface {

	// Install will attempt to install in Kubernetes
	Install(client *kubernetes.Clientset) error

	// Uninstall will attempt to uninstall in Kubernetes
	Uninstall(client *kubernetes.Clientset) error

	// Meta returns the Kubernetes native ObjectMeta which is used to manage applications with naml.
	Meta() *metav1.ObjectMeta

	// Description returns the application description
	Description() string
}

Deployable is an interface that can be implemented for deployable applications.

func Find

func Find(name string) Deployable

Find an application by name

type MainGoValues added in v0.2.6

type MainGoValues struct {
	AuthorName    string
	AuthorEmail   string
	CopyrightYear string
	AppNameTitle  string
	AppNameLower  string
	Description   string
	Version       string
	Install       string
	Uninstall     string
}

MainGoValues are ultimately what is rendered into the .naml files in /src. These values are what will be created in the output.

type RPCApplication

type RPCApplication struct {
	// Name is the name of the remote application
	AppName string

	// Remote is the associated remote RPC server
	Remote *RPCPointer

	// AppDescription is the application description
	AppDescription string

	// AppVersion is the application version
	AppVersion string
}

RPCApplication is the pointer in the parent process to the child process internal application.

func (*RPCApplication) Description

func (c *RPCApplication) Description() string

func (*RPCApplication) Install

func (c *RPCApplication) Install(clientset *kubernetes.Clientset) error

Install is the remote application install wrapper.

func (*RPCApplication) Meta

func (c *RPCApplication) Meta() *v1.ObjectMeta

func (*RPCApplication) Uninstall

func (c *RPCApplication) Uninstall(clientset *kubernetes.Clientset) error

type RPCError

type RPCError struct {
	Message string
}

RPCError is when something goes wrong over the RPC

type RPCPointer

type RPCPointer struct {
	Message string
	Addr    string
}

RPCPointer is a pointer that allows us to connect to a remote RPC server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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