Skip to content

Commit

Permalink
implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Oct 1, 2024
1 parent 005acb6 commit 587458f
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bootstrap/api/v1beta2/ck8sconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ type CK8sConfigSpec struct {
// +optional
AirGapped bool `json:"airGapped,omitempty"`

// Track is the channel to use for the snap install.
// +optional
Track string `json:"track,omitempty"`

// Revision is the revision to use for the snap install.
// If Track is set, this will be ignored.
// +optional
Revision string `json:"revision,omitempty"`

// LocalPath is the local path to use for the snap install.
// If Track or Revision are set, this will be ignored.
// +optional
LocalPath string `json:"localPath,omitempty"`

// CK8sControlPlaneConfig is configuration for the control plane node.
// +optional
ControlPlaneConfig CK8sControlPlaneConfig `json:"controlPlane,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ spec:
the default CNI.
type: boolean
type: object
localPath:
description: |-
LocalPath is the local path to use for the snap install.
If Track or Revision are set, this will be ignored.
type: string
nodeName:
description: |-
NodeName is the name to use for the kubelet of this node. It is needed for clouds
Expand All @@ -210,6 +215,14 @@ spec:
items:
type: string
type: array
revision:
description: |-
Revision is the revision to use for the snap install.
If Track is set, this will be ignored.
type: string
track:
description: Track is the channel to use for the snap install.
type: string
version:
description: Version specifies the Kubernetes version.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ spec:
enable the default CNI.
type: boolean
type: object
localPath:
description: |-
LocalPath is the local path to use for the snap install.
If Track or Revision are set, this will be ignored.
type: string
nodeName:
description: |-
NodeName is the name to use for the kubelet of this node. It is needed for clouds
Expand All @@ -219,6 +224,14 @@ spec:
items:
type: string
type: array
revision:
description: |-
Revision is the revision to use for the snap install.
If Track is set, this will be ignored.
type: string
track:
description: Track is the channel to use for the snap install.
type: string
version:
description: Version specifies the Kubernetes version.
type: string
Expand Down
36 changes: 36 additions & 0 deletions bootstrap/controllers/ck8sconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,16 @@ func (r *CK8sConfigReconciler) joinControlplane(ctx context.Context, scope *Scop
return err
}

// If the machine has an in-place upgrade annotation, use it to determine the snap install data.
snapInstallData := r.resolveInPlaceUpgradeRelease(machine)

// If the snap install data is not set, use the config spec to determine the snap install data.
if snapInstallData == (cloudinit.SnapInstallData{}) {
snapInstallData = r.setSnapInstallDataFromSpec(scope.Config.Spec)
}

r.Log.Info("Snap install data", "data", snapInstallData)

input := cloudinit.JoinControlPlaneInput{
BaseUserData: cloudinit.BaseUserData{
BootCommands: scope.Config.Spec.BootCommands,
Expand Down Expand Up @@ -340,8 +348,14 @@ func (r *CK8sConfigReconciler) joinWorker(ctx context.Context, scope *Scope) err
return err
}

// If the machine has an in-place upgrade annotation, use it to determine the snap install data.
snapInstallData := r.resolveInPlaceUpgradeRelease(machine)

// If the snap install data is not set, use the config spec to determine the snap install data.
if snapInstallData == (cloudinit.SnapInstallData{}) {
snapInstallData = r.setSnapInstallDataFromSpec(scope.Config.Spec)
}

input := cloudinit.JoinWorkerInput{
BaseUserData: cloudinit.BaseUserData{
BootCommands: scope.Config.Spec.BootCommands,
Expand Down Expand Up @@ -430,6 +444,28 @@ func (r *CK8sConfigReconciler) resolveInPlaceUpgradeRelease(machine *clusterv1.M
return cloudinit.SnapInstallData{}
}

func (r *CK8sConfigReconciler) setSnapInstallDataFromSpec(spec bootstrapv1.CK8sConfigSpec) cloudinit.SnapInstallData {
switch {
case spec.Track != "":
return cloudinit.SnapInstallData{
Option: cloudinit.InstallOptionChannel,
Value: spec.Track,
}
case spec.Revision != "":
return cloudinit.SnapInstallData{
Option: cloudinit.InstallOptionRevision,
Value: spec.Revision,
}
case spec.LocalPath != "":
return cloudinit.SnapInstallData{
Option: cloudinit.InstallOptionLocalPath,
Value: spec.LocalPath,
}
default:
return cloudinit.SnapInstallData{}
}
}

// resolveSecretFileContent returns file content fetched from a referenced secret object.
func (r *CK8sConfigReconciler) resolveSecretFileContent(ctx context.Context, ns string, source bootstrapv1.File) ([]byte, error) {
secret := &corev1.Secret{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ spec:
the default CNI.
type: boolean
type: object
localPath:
description: |-
LocalPath is the local path to use for the snap install.
If Track or Revision are set, this will be ignored.
type: string
nodeName:
description: |-
NodeName is the name to use for the kubelet of this node. It is needed for clouds
Expand All @@ -407,6 +412,14 @@ spec:
items:
type: string
type: array
revision:
description: |-
Revision is the revision to use for the snap install.
If Track is set, this will be ignored.
type: string
track:
description: Track is the channel to use for the snap install.
type: string
version:
description: Version specifies the Kubernetes version.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ spec:
to enable the default CNI.
type: boolean
type: object
localPath:
description: |-
LocalPath is the local path to use for the snap install.
If Track or Revision are set, this will be ignored.
type: string
nodeName:
description: |-
NodeName is the name to use for the kubelet of this node. It is needed for clouds
Expand All @@ -384,6 +389,15 @@ spec:
items:
type: string
type: array
revision:
description: |-
Revision is the revision to use for the snap install.
If Track is set, this will be ignored.
type: string
track:
description: Track is the channel to use for the snap
install.
type: string
version:
description: Version specifies the Kubernetes version.
type: string
Expand Down

0 comments on commit 587458f

Please sign in to comment.