externalsecrets

package
v0.2.0-beta.21 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

External Secrets Builders - External Secrets Resource Constructors

Go Reference

The externalsecrets package provides the generated constructors and the admissible sugar for External Secrets Operator Kubernetes resources. These are the low-level building blocks used by Kure's higher-level stack and workflow packages.

Overview

Every kind is built the same way: the generated Create<Kind> wrapper gives you an object carrying identity only, and the upstream external-secrets struct is the construction API — set Spec fields directly, or through the few Set*/Add* helpers the builder contract admits.

Each block on this page is the body of an Example function in example_test.go, which go test runs: it imports this package as externalsecrets, github.com/go-kure/kure/pkg/kubernetes, the upstream API as esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1", metav1 "k8s.io/apimachinery/pkg/apis/meta/v1", time, and fmt for the line that prints what the example built.

Constructors

Every kind this package registers has a generated Create<Kind> wrapper in zz_generated_create.go, produced from the scheme by pkg/kubernetes/internal/gen (make gen-builders, checked by make check-builders in CI). A wrapper delegates to kubernetes.Create[T] and emits TypeMeta and identity only: no default, no label, no spec value. Namespaced kinds take (name, namespace), cluster-scoped kinds take (name).

obj := externalsecrets.CreateExternalSecret("my-secret", "default")
cl := externalsecrets.CreateClusterSecretStore("global-vault")
fmt.Println(obj.Kind, obj.Namespace+"/"+obj.Name, cl.Kind, cl.Name)

There is no second construction path. The config-struct layer this package used to carry (externalsecrets.ExternalSecret(&externalsecrets.ExternalSecretConfig{...}), SecretStore, ClusterSecretStore) was retired by release 2 of the builder contract: it reached 2 of an ExternalSecret's 7 spec fields (secretStoreRef and data) and was otherwise a copy of the assignments below. The release 2 migration notes map every removed field to the upstream field that replaces it. No hand-written Create* helper for a spec fragment remains either — a sub-type that is not a client.Object takes a struct literal, which is shorter and shows every field being set.

The kinds this package registers, their scope, and what stated that scope are rows in the generated Supported kinds and field maturity tables. The sections below are worked examples, not the coverage list.

See the Kubernetes Builders page for the full builder contract: construction, sugar admission classes, purity and the migration ledgers.

Supported Resources

External Secrets
es := externalsecrets.CreateExternalSecret("my-secret", "default")
es.Spec.SecretStoreRef = esv1.SecretStoreRef{Name: "vault", Kind: "ClusterSecretStore"}
es.Spec.Target = esv1.ExternalSecretTarget{Name: "my-secret"}
externalsecrets.AddExternalSecretData(es, esv1.ExternalSecretData{
    SecretKey: "password",
    RemoteRef: esv1.ExternalSecretDataRemoteRef{Key: "secret/data/myapp"},
})
externalsecrets.SetRefreshInterval(es, metav1.Duration{Duration: time.Hour})
fmt.Println(es.Spec.Data[0].SecretKey, es.Spec.RefreshInterval.Duration)
Secret Stores
ss := externalsecrets.CreateSecretStore("aws-store", "default")
externalsecrets.SetSecretStoreProvider(ss, &esv1.SecretStoreProvider{
    AWS: &esv1.AWSProvider{Service: esv1.AWSServiceSecretsManager, Region: "us-east-1"},
})
ss.Spec.Controller = "my-controller"
fmt.Println(ss.Spec.Provider.AWS.Region, ss.Spec.Controller)
Cluster Secret Stores
css := externalsecrets.CreateClusterSecretStore("global-vault")
externalsecrets.SetClusterSecretStoreProvider(css, &esv1.SecretStoreProvider{
    AWS: &esv1.AWSProvider{Service: esv1.AWSServiceSecretsManager, Region: "us-east-1"},
})
fmt.Println(css.Spec.Provider.AWS.Region)

Modifier Functions

Update existing resources:

es := externalsecrets.CreateExternalSecret("my-secret", "default")
ss := externalsecrets.CreateSecretStore("aws-store", "default")
css := externalsecrets.CreateClusterSecretStore("global-vault")
provider := &esv1.SecretStoreProvider{
    AWS: &esv1.AWSProvider{Service: esv1.AWSServiceSecretsManager, Region: "us-east-1"},
}

// Replace the full spec
es.Spec = esv1.ExternalSecretSpec{Target: esv1.ExternalSecretTarget{Name: "my-secret"}}

// Granular updates
externalsecrets.AddExternalSecretData(es, esv1.ExternalSecretData{
    SecretKey: "password",
    RemoteRef: esv1.ExternalSecretDataRemoteRef{Key: "secret/data/myapp"},
})
externalsecrets.AddDataFrom(es, esv1.ExternalSecretDataFromRemoteRef{
    Extract: &esv1.ExternalSecretDataRemoteRef{Key: "secret/data/shared"},
})
es.Spec.SecretStoreRef = esv1.SecretStoreRef{Name: "vault", Kind: "ClusterSecretStore"}

externalsecrets.SetSecretStoreProvider(ss, provider)
ss.Spec.Controller = "my-controller"

externalsecrets.SetClusterSecretStoreProvider(css, provider)
css.Spec.Controller = "global"

// Labels and annotations use the generic helpers, which work over any object
// with ObjectMeta -- this package carries no per-kind metadata helpers
kubernetes.AddLabel(es, "app", "myapp")
kubernetes.AddAnnotation(ss, "desc", "value")
kubernetes.AddLabel(css, "team", "platform")

fmt.Println(len(es.Spec.Data), es.Spec.DataFrom[0].Extract.Key, css.Spec.Controller, es.Labels["app"])

Documentation

Overview

Package externalsecrets exposes the generated constructors and the admissible sugar for External Secrets Operator resources: ExternalSecret, SecretStore and ClusterSecretStore. Each constructor returns a controller-runtime object carrying identity only; the upstream external-secrets struct is the construction API.

## Constructors

Create<Kind> is generated from the registered scheme and emits apiVersion, kind, metadata.name and, for a namespaced kind, metadata.namespace. Spec fields are the caller's own assignments:

es := externalsecrets.CreateExternalSecret("my-secret", "default")
es.Spec.SecretStoreRef = esv1.SecretStoreRef{Name: "vault", Kind: "ClusterSecretStore"}
externalsecrets.AddExternalSecretData(es, esv1.ExternalSecretData{
        SecretKey: "password",
        RemoteRef: esv1.ExternalSecretDataRemoteRef{Key: "secret/data/myapp"},
})

## Update helpers

Functions prefixed with Set or Add write exactly the one field they name and fall into the builder contract's admitted classes: AddExternalSecretData and AddDataFrom append, SetSecretStoreProvider, SetClusterSecretStoreProvider and SetRefreshInterval assign a pointer-typed field. Labels and annotations use the generic kubernetes.AddLabel / kubernetes.AddAnnotation over metav1.Object; this package carries no per-kind metadata helpers.

The config-struct layer this package used to carry — ExternalSecret, SecretStore and ClusterSecretStore taking a *Config — was retired by release 2 of the builder contract; see docs/builder-contract-release-2.md for the field-by-field mapping.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDataFrom

func AddDataFrom(obj *esv1.ExternalSecret, source esv1.ExternalSecretDataFromRemoteRef)

AddDataFrom appends a dataFrom source to an ExternalSecret.

Example
package main

import (
	"fmt"

	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"

	"github.com/go-kure/kure/pkg/kubernetes"
	"github.com/go-kure/kure/pkg/kubernetes/externalsecrets"
)

func main() {
	es := externalsecrets.CreateExternalSecret("my-secret", "default")
	ss := externalsecrets.CreateSecretStore("aws-store", "default")
	css := externalsecrets.CreateClusterSecretStore("global-vault")
	provider := &esv1.SecretStoreProvider{
		AWS: &esv1.AWSProvider{Service: esv1.AWSServiceSecretsManager, Region: "us-east-1"},
	}

	// Replace the full spec
	es.Spec = esv1.ExternalSecretSpec{Target: esv1.ExternalSecretTarget{Name: "my-secret"}}

	// Granular updates
	externalsecrets.AddExternalSecretData(es, esv1.ExternalSecretData{
		SecretKey: "password",
		RemoteRef: esv1.ExternalSecretDataRemoteRef{Key: "secret/data/myapp"},
	})
	externalsecrets.AddDataFrom(es, esv1.ExternalSecretDataFromRemoteRef{
		Extract: &esv1.ExternalSecretDataRemoteRef{Key: "secret/data/shared"},
	})
	es.Spec.SecretStoreRef = esv1.SecretStoreRef{Name: "vault", Kind: "ClusterSecretStore"}

	externalsecrets.SetSecretStoreProvider(ss, provider)
	ss.Spec.Controller = "my-controller"

	externalsecrets.SetClusterSecretStoreProvider(css, provider)
	css.Spec.Controller = "global"

	// Labels and annotations use the generic helpers, which work over any object
	// with ObjectMeta -- this package carries no per-kind metadata helpers
	kubernetes.AddLabel(es, "app", "myapp")
	kubernetes.AddAnnotation(ss, "desc", "value")
	kubernetes.AddLabel(css, "team", "platform")

	fmt.Println(len(es.Spec.Data), es.Spec.DataFrom[0].Extract.Key, css.Spec.Controller, es.Labels["app"])
}
Output:
1 secret/data/shared global myapp

func AddExternalSecretData

func AddExternalSecretData(obj *esv1.ExternalSecret, data esv1.ExternalSecretData)

AddExternalSecretData appends a data entry to the ExternalSecret spec.

Example
package main

import (
	"fmt"
	"time"

	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

	"github.com/go-kure/kure/pkg/kubernetes/externalsecrets"
)

func main() {
	es := externalsecrets.CreateExternalSecret("my-secret", "default")
	es.Spec.SecretStoreRef = esv1.SecretStoreRef{Name: "vault", Kind: "ClusterSecretStore"}
	es.Spec.Target = esv1.ExternalSecretTarget{Name: "my-secret"}
	externalsecrets.AddExternalSecretData(es, esv1.ExternalSecretData{
		SecretKey: "password",
		RemoteRef: esv1.ExternalSecretDataRemoteRef{Key: "secret/data/myapp"},
	})
	externalsecrets.SetRefreshInterval(es, metav1.Duration{Duration: time.Hour})
	fmt.Println(es.Spec.Data[0].SecretKey, es.Spec.RefreshInterval.Duration)
}
Output:
password 1h0m0s

func CreateClusterExternalSecret

func CreateClusterExternalSecret(name string) *externalsecretsv1.ClusterExternalSecret

CreateClusterExternalSecret returns a cluster-scoped external-secrets.io/v1 ClusterExternalSecret carrying TypeMeta and identity only.

func CreateClusterSecretStore

func CreateClusterSecretStore(name string) *externalsecretsv1.ClusterSecretStore

CreateClusterSecretStore returns a cluster-scoped external-secrets.io/v1 ClusterSecretStore carrying TypeMeta and identity only.

func CreateExternalSecret

func CreateExternalSecret(name, namespace string) *externalsecretsv1.ExternalSecret

CreateExternalSecret returns a external-secrets.io/v1 ExternalSecret carrying TypeMeta and identity only.

Example
package main

import (
	"fmt"

	"github.com/go-kure/kure/pkg/kubernetes/externalsecrets"
)

func main() {
	obj := externalsecrets.CreateExternalSecret("my-secret", "default")
	cl := externalsecrets.CreateClusterSecretStore("global-vault")
	fmt.Println(obj.Kind, obj.Namespace+"/"+obj.Name, cl.Kind, cl.Name)
}
Output:
ExternalSecret default/my-secret ClusterSecretStore global-vault

func CreateSecretStore

func CreateSecretStore(name, namespace string) *externalsecretsv1.SecretStore

CreateSecretStore returns a external-secrets.io/v1 SecretStore carrying TypeMeta and identity only.

func SetClusterSecretStoreProvider

func SetClusterSecretStoreProvider(obj *esv1.ClusterSecretStore, provider *esv1.SecretStoreProvider)

SetClusterSecretStoreProvider sets the provider field on the ClusterSecretStore spec.

Example
package main

import (
	"fmt"

	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"

	"github.com/go-kure/kure/pkg/kubernetes/externalsecrets"
)

func main() {
	css := externalsecrets.CreateClusterSecretStore("global-vault")
	externalsecrets.SetClusterSecretStoreProvider(css, &esv1.SecretStoreProvider{
		AWS: &esv1.AWSProvider{Service: esv1.AWSServiceSecretsManager, Region: "us-east-1"},
	})
	fmt.Println(css.Spec.Provider.AWS.Region)
}
Output:
us-east-1

func SetRefreshInterval

func SetRefreshInterval(obj *esv1.ExternalSecret, d metav1.Duration)

SetRefreshInterval sets the polling interval on an ExternalSecret.

func SetSecretStoreProvider

func SetSecretStoreProvider(obj *esv1.SecretStore, provider *esv1.SecretStoreProvider)

SetSecretStoreProvider sets the provider field on the SecretStore spec.

Example
package main

import (
	"fmt"

	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"

	"github.com/go-kure/kure/pkg/kubernetes/externalsecrets"
)

func main() {
	ss := externalsecrets.CreateSecretStore("aws-store", "default")
	externalsecrets.SetSecretStoreProvider(ss, &esv1.SecretStoreProvider{
		AWS: &esv1.AWSProvider{Service: esv1.AWSServiceSecretsManager, Region: "us-east-1"},
	})
	ss.Spec.Controller = "my-controller"
	fmt.Println(ss.Spec.Provider.AWS.Region, ss.Spec.Controller)
}
Output:
us-east-1 my-controller

Types

This section is empty.

Jump to

Keyboard shortcuts

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