Documentation
¶
Overview ¶
Package operator assembles the kubepkg operator. A distribution that embeds kubepkg builds its own operator binary from it: start from DefaultOptions, change defaults, register its own backends, and Run.
Example (Cli) ¶
The matching CLI, with a command of the distribution's own.
package main
import (
"context"
"fmt"
"strings"
"github.com/kuberoot-dev/kubepkg/pkg/cli"
"github.com/kuberoot-dev/kubepkg/pkg/repo"
)
// allowedRegistries admits only versions whose charts come from the
// distribution's own registry.
type allowedRegistries struct{ prefix string }
func (allowedRegistries) AdmitIndex(context.Context, string, []byte, *repo.Index) error { return nil }
func (p allowedRegistries) AdmitVersion(_ context.Context, _, pkg string, v repo.Version) error {
for _, variant := range v.Spec.Variants {
for _, c := range variant.Components {
if c.Chart != nil && !strings.HasPrefix(c.Chart.Repository, p.prefix) {
return fmt.Errorf("%s %s: chart %s is not from %s", pkg, v.Version, c.Chart.Repository, p.prefix)
}
}
}
return nil
}
func main() {
o := cli.DefaultOptions()
o.Name, o.Short, o.APIGroup = "exctl", "Example Platform packages", "packages.example.org"
o.Policy = allowedRegistries{prefix: "oci://registry.example.org/"}
root := cli.NewRootCommand(o)
if err := root.Execute(); err != nil {
panic(err)
}
}
Output:
Example (Operator) ¶
A distribution's operator: its own API group, its own trust rules, the standard flags.
package main
import (
"context"
"flag"
"fmt"
"strings"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/kuberoot-dev/kubepkg/pkg/operator"
"github.com/kuberoot-dev/kubepkg/pkg/repo"
)
// allowedRegistries admits only versions whose charts come from the
// distribution's own registry.
type allowedRegistries struct{ prefix string }
func (allowedRegistries) AdmitIndex(context.Context, string, []byte, *repo.Index) error { return nil }
func (p allowedRegistries) AdmitVersion(_ context.Context, _, pkg string, v repo.Version) error {
for _, variant := range v.Spec.Variants {
for _, c := range variant.Components {
if c.Chart != nil && !strings.HasPrefix(c.Chart.Repository, p.prefix) {
return fmt.Errorf("%s %s: chart %s is not from %s", pkg, v.Version, c.Chart.Repository, p.prefix)
}
}
}
return nil
}
func main() {
opts := operator.DefaultOptions()
opts.Profile.Group = "packages.example.org"
opts.Policy = allowedRegistries{prefix: "oci://registry.example.org/"}
opts.BindFlags(flag.CommandLine)
flag.Parse()
if err := operator.Run(ctrl.SetupSignalHandler(), ctrl.GetConfigOrDie(), opts); err != nil {
panic(err)
}
}
Output:
Index ¶
- func ArgoBackend(env Env) (backend.Backend, controller.Preparer, error)
- func FluxBackend(env Env) (backend.Backend, controller.Preparer, error)
- func HelmBackend(env Env) (backend.Backend, controller.Preparer, error)
- func Run(ctx context.Context, cfg *rest.Config, o *Options) error
- func WerfBackend(env Env) (backend.Backend, controller.Preparer, error)
- type BackendFactory
- type Env
- type Options
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArgoBackend ¶
ArgoBackend installs through Argo CD: an Application per component.
func FluxBackend ¶
FluxBackend installs through Flux: an OCIRepository or HelmRepository and a HelmRelease per component.
func HelmBackend ¶
HelmBackend installs charts in-process with the Helm SDK.
func WerfBackend ¶
WerfBackend installs through Nelm, werf's deployment engine, with charts prepared as for the helm backend.
Types ¶
type BackendFactory ¶
BackendFactory makes a backend and the preparer that puts charts where that backend reads them.
type Env ¶
type Env struct {
Config *rest.Config
Client client.Client
Options *Options
// PlainHTTPRegistries are the registry hosts reached without TLS:
// Options.PlainHTTPRegistries and those every Repository lists. It
// changes while the operator runs.
PlainHTTPRegistries *source.Registries
}
Env is what a backend factory gets to build its backend.
type Options ¶
type Options struct {
Profile controller.Profile
// Backend names the entry of Backends to use.
Backend string
Backends map[string]BackendFactory
// AddToScheme registers extra types a backend needs.
AddToScheme []func(*runtime.Scheme) error
// IndexFetchers fetch repository indexes by URL scheme; Policy admits
// indexes and versions. A distribution adds transports and trust
// rules here.
IndexFetchers repo.Fetchers
Policy repo.Policy
// Mirror, an oci:// registry path, is where every chart and package
// tree is fetched from instead of where it was published, for
// air-gapped clusters; kubepkg bundle import fills it.
Mirror string
// Webhook settings for the image policy (Profile.ImagePolicy): the
// Service in front of the operator, its namespace, the Secret for the
// serving certificate and the MutatingWebhookConfiguration.
WebhookPort int
WebhookService, WebhookNamespace, WebhookSecret, WebhookConfig string
// NelmBinary is the nelm executable (werf backend).
NelmBinary string
// ArgoNamespace and ArgoProject place Applications (argo backend).
ArgoNamespace string
ArgoProject string
CacheDir string
RegistryConfig string
// RegistrySecrets are namespace/name of kubernetes.io/dockerconfigjson
// Secrets with registry credentials, read on every pull and tried
// before RegistryConfig.
RegistrySecrets []string
// PlainHTTPRegistries are registry hosts, host or host:port, reached
// without TLS; Repositories add their own. Every other registry keeps
// TLS.
PlainHTTPRegistries []string
// PlainHTTP reaches every registry without TLS. Deprecated: use
// PlainHTTPRegistries, which does not take public registries off TLS
// along with a local one.
PlainHTTP bool
MetricsAddr string
ProbeAddr string
LeaderElect bool
// PackageWorkers is how many packages are reconciled at once.
PackageWorkers int
// RetryBackoff is how long a change that failed waits before it is
// tried again; each further failure doubles the wait, up to
// RetryBackoffMax.
RetryBackoff time.Duration
RetryBackoffMax time.Duration
// LeaderElectionID defaults to <binary>.<group>.
LeaderElectionID string
}
Options configure the operator.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions are a plain kubepkg installation with the helm and flux backends.