Skip to content

Commit

Permalink
Merge pull request #1543 from gjenkins8/sdkexamples
Browse files Browse the repository at this point in the history
Helm SDK doc section and examples
  • Loading branch information
scottrigby authored Nov 13, 2024
2 parents f376b4c + 4009d9d commit 0d578e7
Show file tree
Hide file tree
Showing 17 changed files with 1,306 additions and 66 deletions.
2 changes: 1 addition & 1 deletion content/en/docs/community/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Community"
weight: 7
weight: 8
---

# Community Guides
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/faq/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Frequently Asked Questions"
weight: 8
weight: 9
aliases: [
"/docs/topics/faq/",
"/docs/faq/"
Expand Down
4 changes: 2 additions & 2 deletions content/en/docs/glossary/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Glossary"
title: "Glossary"
description: "Terms used to describe components of Helm's architecture."
weight: 9
weight: 10
---

# Glossary
Expand Down
4 changes: 4 additions & 0 deletions content/en/docs/sdk/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: "Go SDK"
weight: 7
---
52 changes: 52 additions & 0 deletions content/en/docs/sdk/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: "Examples"
description: "Examples various features if the Helm SDK"
weight: 2
---

This document runs though a series of examples of using the Helm SDK.
Intended to document various SDK functionalities.

The final example shows `main.go` driver ([link](#driver)). That runs the below actions and includes necessary helper functions.

The code for the examples lives in the [helm/helm-www/sdkexamples/](https://github.com/helm/helm-www/sdkexamples) directory.
And is intended to be fully functional.

## Actions


### Install Action

This example installs the given chart/release, for the given version and values:

{{< highlightexamplego file="sdkexamples/install.go" >}}

### Upgrade Action

This example upgrades the given release, with the given chart, version and values:

{{< highlightexamplego file="sdkexamples/upgrade.go" >}}

### Uninstall Action

This example uninstalls the given release

{{< highlightexamplego file="sdkexamples/uninstall.go" >}}

### List Action

This example lists all released charts (in the currently configured namespace)

{{< highlightexamplego file="sdkexamples/list.go" >}}

### Pull Action

This example pulls a chart from an OCI repository

{{< highlightexamplego file="sdkexamples/pull.go" >}}

## Driver

The driver here shows the necessary auxillary functions needed for the Helm SDK actions to function. And shows the above examples in action, to pull, install, update, and uninstall the 'podinfo' chart from an OCI repository.

{{< highlightexamplego file="sdkexamples/main.go" >}}
84 changes: 84 additions & 0 deletions content/en/docs/sdk/gosdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
title: "Introduction"
description: "Introduces the Helm Go SDK"
aliases: ["/docs/gosdk"]
weight: 1
---
Helm's Go SDK enables custom software to leverage Helm charts and Helm's functionality for managing Kubernetes software deployment
(In fact, the Helm CLI is effectively just one such tool!)

Currently, the SDK has been functionally separated from the Helm CLI.
And the SDK can (and is) used by standalone tooling.
The Helm project has committed to API stability for the SDK.
As a warning, the SDK has some rough edges remaining from the initial work to separate the CLI and the SDK. Which the Helm project aims to improve and over time.

Full API documentation can be found at [https://pkg.go.dev/helm.sh/helm/v3](https://pkg.go.dev/helm.sh/helm/v3).

A brief overview of some of the main types of packages and a simple example follows below.
See the [Examples](./examples.md) section for more examples and a more full featured 'driver'.

## Main package overview

- [pkg/action](https://pkg.go.dev/helm.sh/helm/v3/pkg/action):
Contains the main “client” for performing Helm actions.
This is the same package that the CLI is using underneath the hood.
If you just need to perform basic Helm commands from another Go program, this package is for you
- [pkg/chart](https://pkg.go.dev/helm.sh/helm/v3/pkg/chart), [pkg/chartutil](https://pkg.go.dev/helm.sh/helm/v3/pkg/chartutil):
Methods and helpers used for loading and manipulating charts
- [pkg/chart](https://pkg.go.dev/helm.sh/helm/v3/pkg/cli) and its subpackages:
Contains all the handlers for the standard Helm environment variables and its subpackages contain output and values file handling
- [pkg/release](https://pkg.go.dev/helm.sh/helm/v3/pkg/release):
Defines the `Release` object and statuses

There are many more packages besides these, so go check out the documentation for more information!

### Simple example
This is a simple example of doing a `helm list` using the Go SDK.
See the [Examples](./examples.md) section for more full featured examples.

```go
package main

import (
"log"
"os"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
)

func main() {
settings := cli.New()

actionConfig := new(action.Configuration)
// You can pass an empty string instead of settings.Namespace() to list
// all namespaces
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
log.Printf("%+v", err)
os.Exit(1)
}

client := action.NewList(actionConfig)
// Only list deployed
client.Deployed = true
results, err := client.Run()
if err != nil {
log.Printf("%+v", err)
os.Exit(1)
}

for _, rel := range results {
log.Printf("%+v", rel)
}
}

```


## Compatibility

The Helm SDK explicitly follows the Helm backwards compatibility guarantees:

<https://github.com/helm/community/blob/main/hips/hip-0004.md>

That is, break changes will only be made over major versions.
63 changes: 1 addition & 62 deletions content/en/docs/topics/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,68 +83,7 @@ For more information on using the Go SDK, See the [Go SDK section](#go-sdk)
## Go SDK
Helm 3 debuted a completely restructured Go SDK for a better experience when
building software and tools that leverage Helm. Full documentation can be found
at [https://pkg.go.dev/helm.sh/helm/v3](https://pkg.go.dev/helm.sh/helm/v3), but
a brief overview of some of the most common packages and a simple example follow
below.

### Package overview
This is a list of the most commonly used packages with a simple explanation
about each one:

- `pkg/action`: Contains the main “client” for performing Helm actions. This is
the same package that the CLI is using underneath the hood. If you just need
to perform basic Helm commands from another Go program, this package is for
you
- `pkg/{chart,chartutil}`: Methods and helpers used for loading and manipulating
charts
- `pkg/cli` and its subpackages: Contains all the handlers for the standard Helm
environment variables and its subpackages contain output and values file
handling
- `pkg/release`: Defines the `Release` object and statuses

Obviously there are many more packages besides these, so go check out the
documentation for more information!

### Simple example
This is a simple example of doing a `helm list` using the Go SDK:

```go
package main

import (
"log"
"os"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
)

func main() {
settings := cli.New()

actionConfig := new(action.Configuration)
// You can pass an empty string instead of settings.Namespace() to list
// all namespaces
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
log.Printf("%+v", err)
os.Exit(1)
}

client := action.NewList(actionConfig)
// Only list deployed
client.Deployed = true
results, err := client.Run()
if err != nil {
log.Printf("%+v", err)
os.Exit(1)
}

for _, rel := range results {
log.Printf("%+v", rel)
}
}

```
in the [Go SDK Section](../sdk/gosdk.md).

## Storage backends

Expand Down
1 change: 1 addition & 0 deletions layouts/shortcodes/highlightexamplego.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- transform.Highlight (os.ReadFile (.Get "file")) "go" }}
10 changes: 10 additions & 0 deletions sdkexamples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Helm Go SDK examples

This directory implements various Go SDK examples and a "driver".

These examples are fully working, and can be run by:

```
# cd helm-www/sdkexamples
$ go run ./...
```
144 changes: 144 additions & 0 deletions sdkexamples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
module github.com/helm/helm-www/sdkexamples

go 1.21.5

require (
github.com/pkg/errors v0.9.1
helm.sh/helm v2.17.0+incompatible
helm.sh/helm/v3 v3.13.3
)

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/Microsoft/hcsshim v0.11.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/containerd/containerd v1.7.6 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v24.0.6+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rubenv/sql-migrate v1.5.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.1-0.20230825192346-2191a27a6dc5 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.4 // indirect
k8s.io/apiextensions-apiserver v0.28.4 // indirect
k8s.io/apimachinery v0.28.4 // indirect
k8s.io/apiserver v0.28.4 // indirect
k8s.io/cli-runtime v0.28.4 // indirect
k8s.io/client-go v0.28.4 // indirect
k8s.io/component-base v0.28.4 // indirect
k8s.io/helm v2.17.0+incompatible // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubectl v0.28.4 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
oras.land/oras-go v1.2.4 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 0d578e7

Please sign in to comment.