Skip to content

Commit

Permalink
Merge pull request #94 from kris-nova/docs
Browse files Browse the repository at this point in the history
embed, tests, docs
  • Loading branch information
krisnova authored Nov 20, 2021
2 parents 9bbab02 + 960e0f0 commit 2f3105d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ version=$(shell git rev-parse HEAD)

# Global release version.
# Change this to bump the build version!
version="0.3.2"
version="1.0.0"

compile: ## Compile for the local architecture ⚙
@echo "Compiling..."
Expand Down
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,21 @@ There is a "repository" of examples to borrow/fork:
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.

```go
// changelog: naml v1.0.0 breaks Deployable and replaces *kubernetes.Clienset with kubernetes.Interface

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

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

// Uninstall will attempt to uninstall in Kubernetes
Uninstall(client kubernetes.Interface) error
// Install will attempt to install in Kubernetes
Install(client kubernetes.Interface) error

// Meta returns the Kubernetes native ObjectMeta which is used to manage applications with naml.
Meta() *metav1.ObjectMeta
// Uninstall will attempt to uninstall in Kubernetes
Uninstall(client kubernetes.Interface) error

// Description returns the application description
Description() string
// Meta returns a NAML Meta structure which embed Kubernetes *metav1.ObjectMeta
Meta() *AppMeta

// Objects will return the runtime objects defined for each application
Objects() []runtime.Object
// Objects will return the runtime objects defined for each application
Objects() []runtime.Object
}
```

Expand Down
53 changes: 19 additions & 34 deletions embed_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func New{{ .AppNameTitle }}(name, description string) *{{ .AppNameTitle }} {
Description: description,
ObjectMeta: metav1.ObjectMeta{
Name: name,
ResourceVersion: Version,
},
},
}
Expand Down Expand Up @@ -137,65 +138,49 @@ package {{ .PackageName }}
import (
"context"
{{ .Packages }}
{{ .Packages }}
"github.com/kris-nova/naml"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
)
// {{ .AppNameTitle }}Version is the current release of your application.
var {{ .AppNameTitle }}Version string = "{{ .Version }}"
// App is a very important grown up business application.
type App struct {
metav1.ObjectMeta
description string
type {{ .AppNameTitle }} struct {
naml.AppMeta
objects []runtime.Object
// ----------------------------------
// Add your configuration fields here
// ----------------------------------
}
// NewApp will create a new instance of App.
//
// See https://github.com/naml-examples for more examples.
//
// This is where you pass in fields to your application (similar to Values.yaml)
// Example: func NewApp(name string, example string, something int) *App
func NewApp(name, description string) *App {
return &App{
description: description,
ObjectMeta: metav1.ObjectMeta{
Name: name,
ResourceVersion: {{ .AppNameTitle }}Version,
func New{{ .AppNameTitle }}(name, description string) *{{ .AppNameTitle }} {
return &{{ .AppNameTitle }}{
AppMeta: naml.AppMeta{
Description: description,
ObjectMeta: metav1.ObjectMeta{
Name: name,
ResourceVersion: {{ .AppNameTitle }}Version,
},
},
// ----------------------------------
// Add your configuration fields here
// ----------------------------------
}
}
func (a *App) Install(client kubernetes.Interface) error {
func (x *{{ .AppNameTitle }}) Install(client kubernetes.Interface) error {
var err error
{{ .Install }}
return err
}
func (a *App) Uninstall(client kubernetes.Interface) error {
func (x *{{ .AppNameTitle }}) Uninstall(client kubernetes.Interface) error {
var err error
{{ .Uninstall }}
return err
}
func (a *App) Description() string {
return a.description
}
func (a *App) Meta() *metav1.ObjectMeta {
return &a.ObjectMeta
func (x *{{ .AppNameTitle }}) Meta() *naml.AppMeta {
return &x.AppMeta
}
func (a *App) Objects() []runtime.Object {
return a.objects
func (x *{{ .AppNameTitle }}) Objects() []runtime.Object {
return x.objects
}
`
52 changes: 18 additions & 34 deletions src/library.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,48 @@ package {{ .PackageName }}
import (
"context"

{{ .Packages }}
{{ .Packages }}

"github.com/kris-nova/naml"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
)

// {{ .AppNameTitle }}Version is the current release of your application.
var {{ .AppNameTitle }}Version string = "{{ .Version }}"

// App is a very important grown up business application.
type App struct {
metav1.ObjectMeta
description string
type {{ .AppNameTitle }} struct {
naml.AppMeta
objects []runtime.Object
// ----------------------------------
// Add your configuration fields here
// ----------------------------------
}

// NewApp will create a new instance of App.
//
// See https://github.com/naml-examples for more examples.
//
// This is where you pass in fields to your application (similar to Values.yaml)
// Example: func NewApp(name string, example string, something int) *App
func NewApp(name, description string) *App {
return &App{
description: description,
ObjectMeta: metav1.ObjectMeta{
Name: name,
ResourceVersion: {{ .AppNameTitle }}Version,
func New{{ .AppNameTitle }}(name, description string) *{{ .AppNameTitle }} {
return &{{ .AppNameTitle }}{
AppMeta: naml.AppMeta{
Description: description,
ObjectMeta: metav1.ObjectMeta{
Name: name,
ResourceVersion: {{ .AppNameTitle }}Version,
},
},
// ----------------------------------
// Add your configuration fields here
// ----------------------------------
}
}

func (a *App) Install(client kubernetes.Interface) error {
func (x *{{ .AppNameTitle }}) Install(client kubernetes.Interface) error {
var err error
{{ .Install }}
return err
}

func (a *App) Uninstall(client kubernetes.Interface) error {
func (x *{{ .AppNameTitle }}) Uninstall(client kubernetes.Interface) error {
var err error
{{ .Uninstall }}
return err
}

func (a *App) Description() string {
return a.description
func (x *{{ .AppNameTitle }}) Meta() *naml.AppMeta {
return &x.AppMeta
}

func (a *App) Meta() *metav1.ObjectMeta {
return &a.ObjectMeta
func (x *{{ .AppNameTitle }}) Objects() []runtime.Object {
return x.objects
}

func (a *App) Objects() []runtime.Object {
return a.objects
}
1 change: 1 addition & 0 deletions src/main.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func New{{ .AppNameTitle }}(name, description string) *{{ .AppNameTitle }} {
Description: description,
ObjectMeta: metav1.ObjectMeta{
Name: name,
ResourceVersion: Version,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions tests/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestManifests(t *testing.T) {
err := generateCompileRunYAML(filepath.Join("manifests", file.Name()))
if err != nil {
t.Errorf(err.Error())
t.FailNow()
}
}(file.Name())
}
Expand Down

0 comments on commit 2f3105d

Please sign in to comment.