Documentation
¶
Overview ¶
Package kubernetes provides functions to interact with a Kubernetes cluster to the CLI. The package should be used for:
- Fetching status information about the cluster
- Creating, deleting, or migrating resources not managed by Helm
The package should not be used for anything that doesn't just require the Kubernetes API. For example, Terraform and Helm actions should not be accessed by this package.
Index ¶
- Variables
- func ClusterStatus(ctx context.Context, kubeclient kubeClient) (map[string]NodeStatus, error)
- func GetConstellationVersion(ctx context.Context, client DynamicInterface) (updatev1alpha1.NodeVersion, error)
- type DynamicInterface
- type NodeStatus
- type NodeVersionClient
- type StableInterface
- type TargetVersions
- type UpgradeCmdKind
- type Upgrader
- func (u *Upgrader) ApplyTerraformMigrations(ctx context.Context, opts upgrade.TerraformUpgradeOptions) (terraform.ApplyOutput, error)
- func (u *Upgrader) BackupConfigMap(ctx context.Context, name string) error
- func (u *Upgrader) CheckTerraformMigrations(upgradeWorkspace string) error
- func (u *Upgrader) CleanUpTerraformMigrations(upgradeWorkspace string) error
- func (u *Upgrader) CurrentImage(ctx context.Context) (string, error)
- func (u *Upgrader) CurrentKubernetesVersion(ctx context.Context) (string, error)
- func (u *Upgrader) ExtendClusterConfigCertSANs(ctx context.Context, alternativeNames []string) error
- func (u *Upgrader) GetClusterAttestationConfig(ctx context.Context, variant variant.Variant) (config.AttestationCfg, error)
- func (u *Upgrader) GetClusterConfiguration(ctx context.Context) (kubeadmv1beta3.ClusterConfiguration, *corev1.ConfigMap, error)
- func (u *Upgrader) GetMeasurementSalt(ctx context.Context) ([]byte, error)
- func (u *Upgrader) GetUpgradeID() string
- func (u *Upgrader) KubernetesVersion() (string, error)
- func (u *Upgrader) PlanTerraformMigrations(ctx context.Context, opts upgrade.TerraformUpgradeOptions) (bool, error)
- func (u *Upgrader) UpdateAttestationConfig(ctx context.Context, newAttestConfig config.AttestationCfg) error
- func (u *Upgrader) UpgradeHelmServices(ctx context.Context, config *config.Config, idFile clusterid.File, ...) error
- func (u *Upgrader) UpgradeNodeVersion(ctx context.Context, conf *config.Config, force bool) error
Constants ¶
This section is empty.
Variables ¶
var ErrInProgress = errors.New("upgrade in progress")
ErrInProgress signals that an upgrade is in progress inside the cluster.
Functions ¶
func ClusterStatus ¶
func ClusterStatus(ctx context.Context, kubeclient kubeClient) (map[string]NodeStatus, error)
ClusterStatus returns a map from node name to NodeStatus.
func GetConstellationVersion ¶
func GetConstellationVersion(ctx context.Context, client DynamicInterface) (updatev1alpha1.NodeVersion, error)
GetConstellationVersion queries the constellation-version object for a given field.
Types ¶
type DynamicInterface ¶
type DynamicInterface interface {
GetCurrent(ctx context.Context, name string) (*unstructured.Unstructured, error)
Update(ctx context.Context, obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
}
DynamicInterface is a general interface to query custom resources.
type NodeStatus ¶
type NodeStatus struct {
// contains filtered or unexported fields
}
NodeStatus bundles status information about a node.
func NewNodeStatus ¶
func NewNodeStatus(node corev1.Node) NodeStatus
NewNodeStatus returns a new NodeStatus.
func (*NodeStatus) ImageVersion ¶
func (n *NodeStatus) ImageVersion() string
ImageVersion returns the node image of the node.
func (*NodeStatus) KubeletVersion ¶
func (n *NodeStatus) KubeletVersion() string
KubeletVersion returns the kubelet version of the node.
type NodeVersionClient ¶
type NodeVersionClient struct {
// contains filtered or unexported fields
}
NodeVersionClient implements the DynamicInterface interface to interact with NodeVersion objects.
func NewNodeVersionClient ¶
func NewNodeVersionClient(client dynamic.Interface) *NodeVersionClient
NewNodeVersionClient returns a new NodeVersionClient.
func (*NodeVersionClient) GetCurrent ¶
func (u *NodeVersionClient) GetCurrent(ctx context.Context, name string) (*unstructured.Unstructured, error)
GetCurrent returns the current NodeVersion object.
func (*NodeVersionClient) Update ¶
func (u *NodeVersionClient) Update(ctx context.Context, obj *unstructured.Unstructured) (*unstructured.Unstructured, error)
Update updates the NodeVersion object.
type StableInterface ¶ added in v2.9.0
type StableInterface interface {
GetConfigMap(ctx context.Context, name string) (*corev1.ConfigMap, error)
UpdateConfigMap(ctx context.Context, configMap *corev1.ConfigMap) (*corev1.ConfigMap, error)
CreateConfigMap(ctx context.Context, configMap *corev1.ConfigMap) (*corev1.ConfigMap, error)
KubernetesVersion() (string, error)
}
StableInterface is an interface to interact with stable resources.
func NewStableClient ¶ added in v2.9.0
func NewStableClient(kubeconfigPath string) (StableInterface, error)
NewStableClient returns a new StableClient.
type TargetVersions ¶
type TargetVersions struct {
// contains filtered or unexported fields
}
TargetVersions bundles version information about the target versions of a cluster.
func NewTargetVersions ¶
func NewTargetVersions(nodeVersion updatev1alpha1.NodeVersion) (TargetVersions, error)
NewTargetVersions returns the target versions for the cluster.
func (*TargetVersions) Image ¶
func (c *TargetVersions) Image() string
Image return the image version.
func (*TargetVersions) ImagePath ¶
func (c *TargetVersions) ImagePath() string
ImagePath return the image path.
func (*TargetVersions) Kubernetes ¶
func (c *TargetVersions) Kubernetes() string
Kubernetes return the Kubernetes version.
type UpgradeCmdKind ¶ added in v2.9.0
type UpgradeCmdKind int
UpgradeCmdKind is the kind of the upgrade command (check, apply).
const ( // UpgradeCmdKindCheck corresponds to the upgrade check command. UpgradeCmdKindCheck UpgradeCmdKind = iota // UpgradeCmdKindApply corresponds to the upgrade apply command. UpgradeCmdKindApply )
type Upgrader ¶
type Upgrader struct {
// contains filtered or unexported fields
}
Upgrader handles upgrading the cluster's components using the CLI.
func NewUpgrader ¶
func NewUpgrader( ctx context.Context, outWriter io.Writer, upgradeWorkspace, kubeConfigPath string, fileHandler file.Handler, log debugLog, upgradeCmdKind UpgradeCmdKind, ) (*Upgrader, error)
NewUpgrader returns a new Upgrader.
func (*Upgrader) ApplyTerraformMigrations ¶ added in v2.8.0
func (u *Upgrader) ApplyTerraformMigrations(ctx context.Context, opts upgrade.TerraformUpgradeOptions) (terraform.ApplyOutput, error)
ApplyTerraformMigrations applies the migrations planned by PlanTerraformMigrations. If PlanTerraformMigrations has not been executed before, it will return an error. In case of a successful upgrade, the output will be written to the specified file and the old Terraform directory is replaced By the new one.
func (*Upgrader) BackupConfigMap ¶ added in v2.10.0
BackupConfigMap creates a backup of the given config map.
func (*Upgrader) CheckTerraformMigrations ¶ added in v2.8.0
CheckTerraformMigrations checks whether Terraform migrations are possible in the current workspace. If the files that will be written during the upgrade already exist, it returns an error.
func (*Upgrader) CleanUpTerraformMigrations ¶ added in v2.8.0
CleanUpTerraformMigrations cleans up the Terraform migration workspace, for example when an upgrade is aborted by the user.
func (*Upgrader) CurrentImage ¶
CurrentImage returns the currently used image version of the cluster.
func (*Upgrader) CurrentKubernetesVersion ¶
CurrentKubernetesVersion returns the currently used Kubernetes version.
func (*Upgrader) ExtendClusterConfigCertSANs ¶ added in v2.10.0
func (u *Upgrader) ExtendClusterConfigCertSANs(ctx context.Context, alternativeNames []string) error
ExtendClusterConfigCertSANs extends the ClusterConfig stored under "kube-system/kubeadm-config" with the given SANs. Existing SANs are preserved.
func (*Upgrader) GetClusterAttestationConfig ¶ added in v2.8.0
func (u *Upgrader) GetClusterAttestationConfig(ctx context.Context, variant variant.Variant) (config.AttestationCfg, error)
GetClusterAttestationConfig fetches the join-config configmap from the cluster, extracts the config and returns both the full configmap and the attestation config.
func (*Upgrader) GetClusterConfiguration ¶ added in v2.10.0
func (u *Upgrader) GetClusterConfiguration(ctx context.Context) (kubeadmv1beta3.ClusterConfiguration, *corev1.ConfigMap, error)
GetClusterConfiguration fetches the kubeadm-config configmap from the cluster, extracts the config and returns both the full configmap and the ClusterConfiguration.
func (*Upgrader) GetMeasurementSalt ¶ added in v2.10.0
GetMeasurementSalt returns the measurementSalt from the join-config.
func (*Upgrader) GetUpgradeID ¶ added in v2.10.0
GetUpgradeID returns the upgrade ID.
func (*Upgrader) KubernetesVersion ¶
KubernetesVersion returns the version of Kubernetes the Constellation is currently running on.
func (*Upgrader) PlanTerraformMigrations ¶ added in v2.8.0
func (u *Upgrader) PlanTerraformMigrations(ctx context.Context, opts upgrade.TerraformUpgradeOptions) (bool, error)
PlanTerraformMigrations prepares the upgrade workspace and plans the Terraform migrations for the Constellation upgrade. If a diff exists, it's being written to the upgrader's output writer. It also returns a bool indicating whether a diff exists.
func (*Upgrader) UpdateAttestationConfig ¶ added in v2.8.0
func (u *Upgrader) UpdateAttestationConfig(ctx context.Context, newAttestConfig config.AttestationCfg) error
UpdateAttestationConfig fetches the cluster's attestation config, compares them to a new config, and updates the cluster's config if it is different from the new one.
func (*Upgrader) UpgradeHelmServices ¶
func (u *Upgrader) UpgradeHelmServices(ctx context.Context, config *config.Config, idFile clusterid.File, timeout time.Duration, allowDestructive bool, force bool, conformance bool, helmWaitMode helm.WaitMode, masterSecret uri.MasterSecret, serviceAccURI string, validK8sVersion versions.ValidK8sVersion, output terraform.ApplyOutput, ) error
UpgradeHelmServices upgrade helm services.
func (*Upgrader) UpgradeNodeVersion ¶
UpgradeNodeVersion upgrades the cluster's NodeVersion object and in turn triggers image & k8s version upgrades. The versions set in the config are validated against the versions running in the cluster.