Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoGardenTargeted = errors.New("no garden cluster targeted") ErrNoProjectTargeted = errors.New("no project targeted") ErrNoSeedTargeted = errors.New("no seed cluster targeted") ErrNoShootTargeted = errors.New("no shoot targeted") ErrNeitherProjectNorSeedTargeted = errors.New("neither project nor seed are targeted") ErrNoControlPlaneTargeted = errors.New("no control plane targeted") ErrAborted = errors.New("operation aborted") )
Functions ¶
This section is empty.
Types ¶
type FlagCompletors ¶
type FlagCompletors interface { // ShootNames returns all shoots for the current target. // The current target must at least point to a garden. ShootNames(ctx context.Context) ([]string, error) // SeedNames returns all seeds for the current target. // The current target must at least point to a garden. SeedNames(ctx context.Context) ([]string, error) // ProjectNames returns all projects for the currently targeted garden. // The current target must at least point to a garden. ProjectNames(ctx context.Context) ([]string, error) // GardenNames returns all identities and aliases of configured Gardens. GardenNames() ([]string, error) }
FlagCompletors provides a set of functions that lists suitable completion values for targeting while taking the currently targeted garden account.
type Manager ¶
type Manager interface { FlagCompletors // CurrentTarget contains the current target configuration CurrentTarget() (Target, error) // TargetGarden sets the garden target configuration // This implicitly unsets project, seed and shoot target configuration TargetGarden(ctx context.Context, name string) error // TargetProject sets the project target configuration // This implicitly unsets seed and shoot target configuration TargetProject(ctx context.Context, name string) error // TargetSeed sets the seed target configuration // This implicitly unsets project and shoot target configuration TargetSeed(ctx context.Context, name string) error // TargetShoot sets the shoot target configuration // This implicitly unsets seed target configuration // It will also configure appropriate project and seed values if not already set TargetShoot(ctx context.Context, name string) error // TargetControlPlane sets the control plane target flag TargetControlPlane(ctx context.Context) error // UnsetTargetGarden unsets the garden target configuration // This implicitly unsets project, shoot and seed target configuration UnsetTargetGarden(ctx context.Context) (string, error) // UnsetTargetProject unsets the project target configuration // This implicitly unsets shoot target configuration UnsetTargetProject(ctx context.Context) (string, error) // UnsetTargetSeed unsets the garden seed configuration UnsetTargetSeed(ctx context.Context) (string, error) // UnsetTargetShoot unsets the garden shoot configuration UnsetTargetShoot(ctx context.Context) (string, error) // UnsetTargetControlPlane unsets the control plane flag UnsetTargetControlPlane(ctx context.Context) error // TargetMatchPattern replaces the whole target // Garden, Project and Shoot values are determined by matching the provided value // against patterns defined in gardenctl configuration. Some values may only match a subset // of a pattern TargetMatchPattern(ctx context.Context, tf TargetFlags, value string) error // ClientConfig returns the client config for a target ClientConfig(ctx context.Context, t Target) (clientcmd.ClientConfig, error) // WriteClientConfig creates a kubeconfig file in the session directory of the operating system WriteClientConfig(config clientcmd.ClientConfig) (string, error) // SeedClient controller-runtime client for accessing the configured seed cluster SeedClient(ctx context.Context, t Target) (client.Client, error) // ShootClient controller-runtime client for accessing the configured shoot cluster ShootClient(ctx context.Context, t Target) (client.Client, error) // SessionDir is the path of the session directory. All state related to // the current gardenctl shell session will be stored under this directory. SessionDir() string // Configuration returns the current gardenctl configuration Configuration() *config.Config // GardenClient returns a gardenClient for a garden cluster GardenClient(name string) (clientgarden.Client, error) }
Manager sets and gets the current target configuration.
func NewManager ¶
func NewManager(config *config.Config, targetProvider TargetProvider, clientProvider internalclient.Provider, sessionDirectory string) (Manager, error)
NewManager returns a new manager.
type Target ¶
type Target interface { // GardenName returns the currently targeted garden cluster name. GardenName() string // ProjectName returns the currently targeted project name. ProjectName() string // SeedName returns the currently targeted seed cluster name. SeedName() string // ShootName returns the currently targeted shoot cluster name. ShootName() string // ControlPlane returns true if shoot control plane is targeted. ControlPlane() bool // WithGardenName returns a copy of the target with the garden name updated. // The returned target can be invalid. WithGardenName(name string) Target // WithProjectName returns a copy of the target with the project name updated. // The returned target can be invalid. WithProjectName(name string) Target // WithSeedName returns a copy of the target with the seed name updated. // The returned target can be invalid. WithSeedName(name string) Target // WithShootName returns a copy of the target with the shoot name updated. // The returned target can be invalid. WithShootName(name string) Target // WithControlPlane returns a copy of the target with the control plane flag updated. // The returned target can be invalid. WithControlPlane(controlPlane bool) Target // Validate checks for semantical correctness of the target, without // actually connecting to the targeted clusters. Validate() error // IsEmpty returns true if all values of the target are empty IsEmpty() bool // AsListOption returns the target as list option AsListOption() client.ListOption // DeepCopy returns a deep copy of the target DeepCopy() Target }
Target represents the Kubernetes cluster/namespace which should be the target for user operations in gardenctl. It works similar to the context defined in a kubeconfig.
type TargetBuilder ¶
type TargetBuilder interface { // Init updates the TargetBuilder with the provided target // Use this function to overwrite target baseline data before updating with new values Init(Target) TargetBuilder // SetGarden updates TargetBuilder with a Garden name SetGarden(string) TargetBuilder // SetProject updates TargetBuilder with a Project name SetProject(context.Context, string) TargetBuilder // SetNamespace updates TargetBuilder with a Namespace name // The Namespace will be used to resolve the associated project during build SetNamespace(context.Context, string) TargetBuilder // SetSeed updates TargetBuilder with a Seed name SetSeed(context.Context, string) TargetBuilder // SetShoot updates TargetBuilder with a Shoot name SetShoot(context.Context, string) TargetBuilder // SetControlPlane updates TargetBuilder shoot control plane flag SetControlPlane(context.Context) TargetBuilder // Build uses the values set for TargetBuilder to create and return a new target // This function validates the target values and tries to complete missing values // If the provided values do not represent a valid and unique target, an error is returned Build() (Target, error) }
TargetBuilder builds, completes and validates target values to create valid targets.
func NewTargetBuilder ¶
func NewTargetBuilder(config *config.Config, clientProvider internalclient.Provider) (TargetBuilder, error)
NewTargetBuilder returns a new target builder.
type TargetFlags ¶
type TargetFlags interface { // GardenName returns the value that is tied to the corresponding cobra flag. GardenName() string // ProjectName returns the value that is tied to the corresponding cobra flag. ProjectName() string // SeedName returns the value that is tied to the corresponding cobra flag. SeedName() string // ShootName returns the value that is tied to the corresponding cobra flag. ShootName() string // ControlPlane returns the value that is tied to the corresponding cobra flag. ControlPlane() bool // AddFlags binds all target configuration flags to a given flagset AddFlags(flags *pflag.FlagSet) // AddGardenFlag adds the garden flag to the provided flag set AddGardenFlag(flags *pflag.FlagSet) // AddProjectFlag adds the project flag to the provided flag set AddProjectFlag(flags *pflag.FlagSet) // AddSeedFlag adds the seed flag to the provided flag set AddSeedFlag(flags *pflag.FlagSet) // AddShootFlag adds the shoot flag to the provided flag set AddShootFlag(flags *pflag.FlagSet) // AddControlPlaneFlag adds the control-plane flag to the provided flag set AddControlPlaneFlag(flags *pflag.FlagSet) // ToTarget converts the flags to a target ToTarget() Target // IsTargetValid returns true if the set of given CLI flags is enough // to create a meaningful target. For example, if only the SeedName is // given, false is returned because for targeting a seed, the GardenName // must also be given. If ShootName and GardenName are set, false is // returned because either project or seed have to be given as well. IsTargetValid() bool // IsEmpty returns true if no flags were given by the user IsEmpty() bool }
TargetFlags represents the target cobra flags.
func NewTargetFlags ¶
func NewTargetFlags(garden, project, seed, shoot string, controlPlane bool) TargetFlags
type TargetProvider ¶
type TargetProvider interface { TargetReader TargetWriter }
TargetProvider can read and write targets.
func NewTargetProvider ¶
func NewTargetProvider(targetFile string, targetFlags TargetFlags) TargetProvider
NewTargetProvider returns a new TargetProvider that reads and writes the current Target.
type TargetReader ¶
type TargetReader interface { // Read returns the current target. If no target exists yet, a default // (empty) target is returned. Read() (Target, error) }
TargetReader can read targets.
type TargetWriter ¶
type TargetWriter interface { // Write takes a target and saves it permanently. Write(t Target) error }
TargetWriter can write targets.