fluxexec

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

README

Flux Exec (fluxexec)

Introduction

This package provides a wrapper of the command line interface to execute Flux commands.

How to add new flags

Add the new type Option struct to the options.go of fluxexec package. Then create a function to represent it.

The below example shows how to add the --export flag. We have ExportOption struct to whole the value of the --export flag, and we have Export function to represent this flag during the command creation.

type ExportOption struct {
	export bool
}

// Export represents the --export flag.
func Export(export bool) *ExportOption {
	return &ExportOption{export}
}

After that we go to each command wrapper file, for example we have install.go file as the wrapper of flux install command, and we have bootstrap_github.go file as the wrapper of the flux bootstrap github command.

Following the above example, we add the --export flag to the wrapper of the install command.

First, find the installConfig struct in the install.go file. Then, add the export field to the struct.

type installConfig struct {
	clusterDomain      string
	components         []string
	componentsExtra    []string
	export             bool     // Here's our new export field
	imagePullSecret    string
	logLevel           string
	networkPolicy      bool
	registry           string
	tolerationKeys     []string
	watchAllNamespaces bool
}

Then, we add the configureInstall function for the ExportOption struct. This function will be called to configure the installConfig struct, by setting the value of the export field.

func (opt *ExportOption) configureInstall(conf *installConfig) {
	conf.export = opt.export
}

Next, locate the installCmd function.

func (flux *Flux) installCmd(ctx context.Context, opts ...InstallOption) (*exec.Cmd, error) {

This function will be called to create the command, with all the flags as args. We add the following if statement to help this command generate the --export flag.

	if c.export && !reflect.DeepEqual(c.export, defaultInstallOptions.export) {
		args = append(args, "--export")
	}
Revisiting the package for a new Flux version

When a new version of Flux is released, the fluxexec package needs to be revisited to ensure that all the new flags are added. To do so, we need to check the flux install and flux bootstrap commands to see if there are any new flags added.

For example, running the following command to check if there's a new default value: flux install --help | grep "(default"

$ flux install --help | grep "(default"
      --cluster-domain string      internal cluster domain (default "cluster.local")
      --components strings         list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
      --log-level logLevel         log level, available options are: (debug, info, error) (default info)
      --network-policy             deny ingress access to the toolkit controllers from other namespaces using network policies (default true)
      --registry string            container registry where the toolkit images are published (default "ghcr.io/fluxcd")
      --watch-all-namespaces       watch for custom resources in all namespaces, if set to false it will only watch the namespace where the toolkit is installed (default true)

Here's the new flags from the global scope in the flux install command.

      --cache-dir string               Default cache directory (default "/home/user/.kube/cache")
      --kube-api-burst int             The maximum burst queries-per-second of requests sent to the Kubernetes API. (default 100)
      --kube-api-qps float32           The maximum queries-per-second of requests sent to the Kubernetes API. (default 50)
  -n, --namespace string               If present, the namespace scope for this CLI request (default "flux-system")
      --timeout duration               timeout for this operation (default 5m0s)
Future Improvements

The current implementation of the fluxexec package is not ideal. It is not easy to add new flags, and it is not easy to maintain. We need to find a better way to implement this package. For example, we would write a script to generate the code of this package for us, instead of writing the code manually. It would be done by parsing the flux install and flux bootstrap commands, and generate the code based on the flags.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowInsecureHTTPOption added in v0.9.5

type AllowInsecureHTTPOption struct {
	// contains filtered or unexported fields
}

func AllowInsecureHTTP added in v0.9.5

func AllowInsecureHTTP(allowInsecureHTTP bool) *AllowInsecureHTTPOption

AllowInsecureHTTP represents the --allow-insecure-http flag.

type AsGroupOption added in v0.9.5

type AsGroupOption struct {
	// contains filtered or unexported fields
}

func AsGroup added in v0.9.5

func AsGroup(asGroup ...string) *AsGroupOption

AsGroup represents the --as-group flag.

type AsOption added in v0.9.5

type AsOption struct {
	// contains filtered or unexported fields
}

func As added in v0.9.5

func As(as string) *AsOption

As represents the --as flag.

type AsUIDOption added in v0.9.5

type AsUIDOption struct {
	// contains filtered or unexported fields
}

func AsUID added in v0.9.5

func AsUID(asUID string) *AsUIDOption

AsUID represents the --as-uid flag.

type AuthorEmailOption

type AuthorEmailOption struct {
	// contains filtered or unexported fields
}

func AuthorEmail

func AuthorEmail(authorEmail string) *AuthorEmailOption

AuthorEmail represents the --author-email flag.

type AuthorNameOption

type AuthorNameOption struct {
	// contains filtered or unexported fields
}

func AuthorName

func AuthorName(authorName string) *AuthorNameOption

AuthorName represents the --author-name flag.

type BootstrapBitbucketServerOption added in v0.9.5

type BootstrapBitbucketServerOption interface {
	// contains filtered or unexported methods
}

BootstrapBitbucketServerOption represents options used in the BootstrapBitbucketServer method.

type BootstrapGitHubOption

type BootstrapGitHubOption interface {
	// contains filtered or unexported methods
}

BootstrapGitHubOption represents options used in the BootstrapGitHub method.

type BootstrapGitLabOption added in v0.9.5

type BootstrapGitLabOption interface {
	// contains filtered or unexported methods
}

BootstrapGitLabOption represents options used in the BootstrapGitLab method.

type BootstrapGitOption added in v0.9.5

type BootstrapGitOption interface {
	// contains filtered or unexported methods
}

BootstrapGitOption represents options used in the BootstrapGit method.

type BootstrapOption

type BootstrapOption interface {
	// contains filtered or unexported methods
}

BootstrapOption represents options used in the Bootstrap* methods.

type BootstrapOptions

type BootstrapOptions struct {
	// contains filtered or unexported fields
}

BootstrapOptions is a special set of options for the (parent) bootstrap command.

func WithBootstrapOptions

func WithBootstrapOptions(opts ...BootstrapOption) *BootstrapOptions

type BranchOption

type BranchOption struct {
	// contains filtered or unexported fields
}

func Branch

func Branch(branch string) *BranchOption

Branch represents the --branch flag.

type CaFileOption

type CaFileOption struct {
	// contains filtered or unexported fields
}

func CaFile

func CaFile(caFile string) *CaFileOption

CaFile represents the --ca-file flag.

type CacheDirOption added in v0.9.5

type CacheDirOption struct {
	// contains filtered or unexported fields
}

func CacheDir added in v0.9.5

func CacheDir(cacheDir string) *CacheDirOption

CacheDir represents the --cache-dir flag.

type CertificateAuthorityOption added in v0.9.5

type CertificateAuthorityOption struct {
	// contains filtered or unexported fields
}

func CertificateAuthority added in v0.9.5

func CertificateAuthority(certificateAuthority string) *CertificateAuthorityOption

CertificateAuthority represents the --certificate-authority flag.

type ClientCertificateOption added in v0.9.5

type ClientCertificateOption struct {
	// contains filtered or unexported fields
}

func ClientCertificate added in v0.9.5

func ClientCertificate(clientCertificate string) *ClientCertificateOption

ClientCertificate represents the --client-certificate flag.

type ClientKeyOption added in v0.9.5

type ClientKeyOption struct {
	// contains filtered or unexported fields
}

func ClientKey added in v0.9.5

func ClientKey(clientKey string) *ClientKeyOption

ClientKey represents the --client-key flag.

type ClusterDomainOption

type ClusterDomainOption struct {
	// contains filtered or unexported fields
}

func ClusterDomain

func ClusterDomain(clusterDomain string) *ClusterDomainOption

ClusterDomain represents the --cluster-domain flag.

type ClusterOption added in v0.9.5

type ClusterOption struct {
	// contains filtered or unexported fields
}

func Cluster added in v0.9.5

func Cluster(cluster string) *ClusterOption

Cluster represents the --cluster flag.

type CommitMessageAppendixOption

type CommitMessageAppendixOption struct {
	// contains filtered or unexported fields
}

func CommitMessageAppendix

func CommitMessageAppendix(commitMessageAppendix string) *CommitMessageAppendixOption

CommitMessageAppendix represents the --commit-message-appendix flag.

type Component

type Component string
const (
	ComponentSourceController       Component = "source-controller"
	ComponentKustomizeController    Component = "kustomize-controller"
	ComponentHelmController         Component = "helm-controller"
	ComponentNotificationController Component = "notification-controller"
)

type ComponentExtra

type ComponentExtra string
const (
	ComponentImageReflectorController  ComponentExtra = "image-reflector-controller"
	ComponentImageAutomationController ComponentExtra = "image-automation-controller"
)

type ComponentsExtraOption

type ComponentsExtraOption struct {
	// contains filtered or unexported fields
}

func ComponentsExtra

func ComponentsExtra(componentsExtra ...ComponentExtra) *ComponentsExtraOption

ComponentsExtra represents the --components-extra flag.

type ComponentsOption

type ComponentsOption struct {
	// contains filtered or unexported fields
}

func Components

func Components(components ...Component) *ComponentsOption

Components represents the --components flag.

type ContextOption added in v0.9.5

type ContextOption struct {
	// contains filtered or unexported fields
}

func KubeContext added in v0.9.5

func KubeContext(context string) *ContextOption

KubeContext represents the --context flag.

type ECDSACurve added in v0.9.5

type ECDSACurve string
const (
	ECDSACurveP256 ECDSACurve = "p256"
	ECDSACurveP384 ECDSACurve = "p384"
	ECDSACurveP521 ECDSACurve = "p521"
)

type ErrNoSuitableBinary

type ErrNoSuitableBinary struct {
	// contains filtered or unexported fields
}

func (*ErrNoSuitableBinary) Error

func (e *ErrNoSuitableBinary) Error() string

func (*ErrNoSuitableBinary) Unwrap

func (e *ErrNoSuitableBinary) Unwrap() error

type ExportOption

type ExportOption struct {
	// contains filtered or unexported fields
}

func Export

func Export(export bool) *ExportOption

Export represents the --export flag.

type Flux

type Flux struct {
	// contains filtered or unexported fields
}

func NewFlux

func NewFlux(workingDir, execPath string) (*Flux, error)

func (*Flux) BootstrapBitbucketServer added in v0.9.5

func (flux *Flux) BootstrapBitbucketServer(ctx context.Context, opts ...BootstrapBitbucketServerOption) error

func (*Flux) BootstrapGit added in v0.9.5

func (flux *Flux) BootstrapGit(ctx context.Context, opts ...BootstrapGitOption) error

func (*Flux) BootstrapGitHub

func (flux *Flux) BootstrapGitHub(ctx context.Context, opts ...BootstrapGitHubOption) error

func (*Flux) BootstrapGitlab added in v0.9.5

func (flux *Flux) BootstrapGitlab(ctx context.Context, opts ...BootstrapGitLabOption) error

func (*Flux) ExecPath

func (flux *Flux) ExecPath() string

ExecPath returns the path to the Flux executable.

func (*Flux) Install

func (flux *Flux) Install(ctx context.Context, opts ...InstallOption) error

func (*Flux) SetEnvVar added in v0.10.0

func (flux *Flux) SetEnvVar(key, value string)

func (*Flux) SetLogger

func (flux *Flux) SetLogger(logger logr.Logger)

SetLogger specifies a logger for tfexec to use.

func (*Flux) WorkingDir

func (flux *Flux) WorkingDir() string

WorkingDir returns the working directory for Flux.

type GPGKeyIDOption added in v0.9.5

type GPGKeyIDOption struct {
	// contains filtered or unexported fields
}

func GPGKeyID added in v0.9.5

func GPGKeyID(gpgKeyID string) *GPGKeyIDOption

GPGKeyID represents the --gpg-key-id flag.

type GPGKeyRingOption added in v0.9.5

type GPGKeyRingOption struct {
	// contains filtered or unexported fields
}

func GPGKeyRing added in v0.9.5

func GPGKeyRing(gpgKeyRing string) *GPGKeyRingOption

GPGKeyRing represents the --gpg-key-ring flag.

type GPGPassphraseOption added in v0.9.5

type GPGPassphraseOption struct {
	// contains filtered or unexported fields
}

func GPGPassphrase added in v0.9.5

func GPGPassphrase(gpgPassphrase string) *GPGPassphraseOption

GPGPassphrase represents the --gpg-passphrase flag.

type GlobalOption added in v0.9.5

type GlobalOption interface {
	// contains filtered or unexported methods
}

GlobalOption represents options used in the Global* methods.

type GlobalOptions added in v0.9.5

type GlobalOptions struct {
	// contains filtered or unexported fields
}

GlobalOptions is a special set of options for the (parent) global command.

func WithGlobalOptions added in v0.9.5

func WithGlobalOptions(opts ...GlobalOption) *GlobalOptions

type GroupOption added in v0.9.5

type GroupOption struct {
	// contains filtered or unexported fields
}

func Group added in v0.9.5

func Group(group ...string) *GroupOption

Group represents the --group flag. Bitbucket Server groups to be given write access (also accepts comma-separated values)

type HostnameOption

type HostnameOption struct {
	// contains filtered or unexported fields
}

func Hostname

func Hostname(hostname string) *HostnameOption

Hostname represents the --hostname flag.

type ImagePullSecretOption

type ImagePullSecretOption struct {
	// contains filtered or unexported fields
}

func ImagePullSecret

func ImagePullSecret(imagePullSecret string) *ImagePullSecretOption

ImagePullSecret represents the --image-pull-secret flag.

type InsecureSkipTLSVerifyOption added in v0.9.5

type InsecureSkipTLSVerifyOption struct {
	// contains filtered or unexported fields
}

func InsecureSkipTLSVerify added in v0.9.5

func InsecureSkipTLSVerify(insecureSkipTLSVerify bool) *InsecureSkipTLSVerifyOption

InsecureSkipTLSVerify represents the --insecure-skip-tls-verify flag.

type InstallOption

type InstallOption interface {
	// contains filtered or unexported methods
}

InstallOption represents options used in the Install method.

type IntervalOption

type IntervalOption struct {
	// contains filtered or unexported fields
}

func Interval

func Interval(interval string) *IntervalOption

Interval represents the --interval flag.

type KeyAlgorithm

type KeyAlgorithm string
const (
	KeyAlgorithmRSA     KeyAlgorithm = "rsa"
	KeyAlgorithmECDSA   KeyAlgorithm = "ecdsa"
	KeyAlgorithmED25519 KeyAlgorithm = "ed25519"
)

type KubeAPIBurstOption added in v0.9.5

type KubeAPIBurstOption struct {
	// contains filtered or unexported fields
}

func KubeAPIBurst added in v0.9.5

func KubeAPIBurst(kubeAPIBurst int) *KubeAPIBurstOption

KubeAPIBurst represents the --kube-api-burst flag.

type KubeAPIQPSOption added in v0.9.5

type KubeAPIQPSOption struct {
	// contains filtered or unexported fields
}

func KubeAPIQPS added in v0.9.5

func KubeAPIQPS(kubeAPIQPS float32) *KubeAPIQPSOption

KubeAPIQPS represents the --kube-api-qps flag.

type KubeconfigOption added in v0.9.5

type KubeconfigOption struct {
	// contains filtered or unexported fields
}

func Kubeconfig added in v0.9.5

func Kubeconfig(kubeconfig string) *KubeconfigOption

Kubeconfig represents the --kubeconfig flag.

type LogLevelOption

type LogLevelOption struct {
	// contains filtered or unexported fields
}

func LogLevel

func LogLevel(logLevel string) *LogLevelOption

LogLevel represents the --log-level flag.

type NamespaceOption added in v0.9.5

type NamespaceOption struct {
	// contains filtered or unexported fields
}

func Namespace added in v0.9.5

func Namespace(namespace string) *NamespaceOption

Namespace represents the --namespace flag.

type NetworkPolicyOption

type NetworkPolicyOption struct {
	// contains filtered or unexported fields
}

func NetworkPolicy

func NetworkPolicy(networkPolicy bool) *NetworkPolicyOption

NetworkPolicy represents the --network-policy flag.

type OwnerOption

type OwnerOption struct {
	// contains filtered or unexported fields
}

func Owner

func Owner(owner string) *OwnerOption

Owner represents the --owner flag.

type PasswordOption added in v0.9.5

type PasswordOption struct {
	// contains filtered or unexported fields
}

func Password added in v0.9.5

func Password(password string) *PasswordOption

Password represents the --password flag.

type PathOption

type PathOption struct {
	// contains filtered or unexported fields
}

func Path

func Path(path string) *PathOption

Path represents the --path flag.

type PersonalOption

type PersonalOption struct {
	// contains filtered or unexported fields
}

func Personal

func Personal(personal bool) *PersonalOption

Personal represents the --personal flag.

type PrivateKeyFileOption

type PrivateKeyFileOption struct {
	// contains filtered or unexported fields
}

func PrivateKeyFile

func PrivateKeyFile(privateKeyFile string) *PrivateKeyFileOption

PrivateKeyFile represents the --private-key-file flag.

type PrivateOption

type PrivateOption struct {
	// contains filtered or unexported fields
}

func Private

func Private(private bool) *PrivateOption

Private represents the --private flag.

type ReadWriteKeyOption

type ReadWriteKeyOption struct {
	// contains filtered or unexported fields
}

func ReadWriteKey

func ReadWriteKey(readWriteKey bool) *ReadWriteKeyOption

ReadWriteKey represents the --read-write-key flag.

type ReconcileOption

type ReconcileOption struct {
	// contains filtered or unexported fields
}

func Reconcile

func Reconcile(reconcile bool) *ReconcileOption

Reconcile represents the --reconcile flag.

type RecurseSubmodulesOption

type RecurseSubmodulesOption struct {
	// contains filtered or unexported fields
}

func RecurseSubmodules

func RecurseSubmodules(recurseSubmodules bool) *RecurseSubmodulesOption

RecurseSubmodules represents the --recurse-submodules flag.

type RegistryOption

type RegistryOption struct {
	// contains filtered or unexported fields
}

func Registry

func Registry(registry string) *RegistryOption

Registry represents the --registry flag.

type RepositoryOption

type RepositoryOption struct {
	// contains filtered or unexported fields
}

func Repository

func Repository(repository string) *RepositoryOption

Repository represents the --repository flag.

type SSHECDSACurveOption added in v0.9.5

type SSHECDSACurveOption struct {
	// contains filtered or unexported fields
}

func SSHECDSACurve added in v0.9.5

func SSHECDSACurve(ecdsaCurve ECDSACurve) *SSHECDSACurveOption

SSHECDSACurve represents the --ssh-ecdsa-curve flag.

type SSHHostnameOption added in v0.9.5

type SSHHostnameOption struct {
	// contains filtered or unexported fields
}

func SSHHostname added in v0.9.5

func SSHHostname(sshHostname string) *SSHHostnameOption

SSHHostname represents the --ssh-hostname flag.

type SSHKeyAlgorithmOption added in v0.9.5

type SSHKeyAlgorithmOption struct {
	// contains filtered or unexported fields
}

func SSHKeyAlgorithm added in v0.9.5

func SSHKeyAlgorithm(sshKeyAlgorithm KeyAlgorithm) *SSHKeyAlgorithmOption

SSHKeyAlgorithm represents the --ssh-key-algorithm flag.

type SSHRSABitsOption added in v0.9.5

type SSHRSABitsOption struct {
	// contains filtered or unexported fields
}

func SSHRSABits added in v0.9.5

func SSHRSABits(sshRSABits int) *SSHRSABitsOption

SSHRSABits represents the --ssh-rsa-bits flag.

type SecretNameOption

type SecretNameOption struct {
	// contains filtered or unexported fields
}

func SecretName

func SecretName(secretName string) *SecretNameOption

SecretName represents the --secret-name flag.

type ServerOption added in v0.9.5

type ServerOption struct {
	// contains filtered or unexported fields
}

func Server added in v0.9.5

func Server(server string) *ServerOption

Server represents the --server flag.

type SilentOption added in v0.9.5

type SilentOption struct {
	// contains filtered or unexported fields
}

func Silent added in v0.9.5

func Silent(silent bool) *SilentOption

Silent represents the --silent flag.

type TLSServerNameOption added in v0.9.5

type TLSServerNameOption struct {
	// contains filtered or unexported fields
}

func TLSServerName added in v0.9.5

func TLSServerName(tlsServerName string) *TLSServerNameOption

TLSServerName represents the --tls-server-name flag.

type TeamOption

type TeamOption struct {
	// contains filtered or unexported fields
}

func Team

func Team(team ...string) *TeamOption

Team represents the --team flag.

type TimeoutOption added in v0.9.5

type TimeoutOption struct {
	// contains filtered or unexported fields
}

func Timeout added in v0.9.5

func Timeout(timeout time.Duration) *TimeoutOption

Timeout represents the --timeout flag.

type TokenAuthOption

type TokenAuthOption struct {
	// contains filtered or unexported fields
}

func TokenAuth

func TokenAuth(tokenAuth bool) *TokenAuthOption

TokenAuth represents the --token-auth flag.

type TokenOption added in v0.9.5

type TokenOption struct {
	// contains filtered or unexported fields
}

func Token added in v0.9.5

func Token(token string) *TokenOption

Token represents the --token flag.

type TolerationKeysOption

type TolerationKeysOption struct {
	// contains filtered or unexported fields
}

func TolerationKeys

func TolerationKeys(tolerationKeys ...string) *TolerationKeysOption

TolerationKeys represents the --toleration-keys flag.

type URLOption added in v0.9.5

type URLOption struct {
	// contains filtered or unexported fields
}

func URL added in v0.9.5

func URL(url string) *URLOption

URL represents the --url flag.

type UserOption added in v0.9.5

type UserOption struct {
	// contains filtered or unexported fields
}

func User added in v0.9.5

func User(user string) *UserOption

User represents the --user flag.

type UsernameOption added in v0.9.5

type UsernameOption struct {
	// contains filtered or unexported fields
}

func Username added in v0.9.5

func Username(username string) *UsernameOption

Username represents the --username flag.

type VerboseOption added in v0.9.5

type VerboseOption struct {
	// contains filtered or unexported fields
}

func Verbose added in v0.9.5

func Verbose(verbose bool) *VerboseOption

Verbose represents the --verbose flag.

type VersionOption added in v0.9.6

type VersionOption struct {
	// contains filtered or unexported fields
}

func Version added in v0.9.6

func Version(version string) *VersionOption

Version represents the --version flag.

type WatchAllNamespacesOption

type WatchAllNamespacesOption struct {
	// contains filtered or unexported fields
}

func WatchAllNamespaces

func WatchAllNamespaces(watchAllNamespaces bool) *WatchAllNamespacesOption

WatchAllNamespaces represents the --watch-all-namespaces flag.

Jump to

Keyboard shortcuts

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