Skip to content

Commit

Permalink
Add methods to fetch upgrader image from bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
taneyland committed Jan 10, 2024
1 parent ed36457 commit 57c6084
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ spec:
spec:
description: ControlPlaneUpgradeSpec defines the desired state of ControlPlaneUpgrade.
properties:
cluster:
properties:
kind:
type: string
name:
type: string
type: object
controlPlane:
properties:
kind:
Expand All @@ -70,13 +63,15 @@ spec:
type: string
type: object
type: array
upgraderImage:
type: string
required:
- cluster
- controlPlane
- kubeadmClusterConfig
- kubeletVersion
- kubernetesVersion
- machinesRequireUpgrade
- upgraderImage
type: object
status:
description: ControlPlaneUpgradeStatus defines the observed state of ControlPlaneUpgrade.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ spec:
description: MachineDeploymentUpgradeSpec defines the desired state of
MachineDeploymentUpgrade.
properties:
cluster:
properties:
kind:
type: string
name:
type: string
type: object
kubeadmClusterConfig:
type: string
kubeletVersion:
Expand All @@ -67,13 +60,15 @@ spec:
type: string
type: object
type: array
upgraderImage:
type: string
required:
- cluster
- kubeadmClusterConfig
- kubeletVersion
- kubernetesVersion
- machineDeployment
- machinesRequireUpgrade
- upgraderImage
type: object
status:
description: MachineDeploymentUpgradeStatus defines the observed state
Expand Down
5 changes: 3 additions & 2 deletions config/crd/bases/anywhere.eks.amazonaws.com_nodeupgrades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ spec:
nodes and ignored for worker nodes.
type: boolean
kubernetesVersion:
description: 'TODO(in-place): Determine if there''s a way to get these
dynamically instead of expecting it from the CRD.'
type: string
machine:
description: Machine is a reference to the CAPI Machine that needs
Expand Down Expand Up @@ -86,9 +84,12 @@ spec:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
upgraderImage:
type: string
required:
- kubernetesVersion
- machine
- upgraderImage
type: object
status:
description: NodeUpgradeStatus defines the observed state of NodeUpgrade.
Expand Down
56 changes: 36 additions & 20 deletions config/manifest/eksa-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3740,24 +3740,51 @@ spec:
in the cluster
properties:
cilium:
description: CiliumConfig contains configuration specific
to the Cilium CNI.
properties:
egressMasqueradeInterfaces:
description: EgressMasquaradeInterfaces determines which
network interfaces are used for masquerading. Accepted
values are a valid interface name or interface prefix.
type: string
ipv4NativeRoutingCIDR:
description: IPv4NativeRoutingCIDR specifies the CIDR
to use when RoutingMode is set to direct. When specified,
Cilium assumes networking for this CIDR is preconfigured
and hands traffic destined for that range to the Linux
network stack without applying any SNAT. If this is
not set autoDirectNodeRoutes will be set to true
type: string
ipv6NativeRoutingCIDR:
description: IPv6NativeRoutingCIDR specifies the IPv6
CIDR to use when RoutingMode is set to direct. When
specified, Cilium assumes networking for this CIDR is
preconfigured and hands traffic destined for that range
to the Linux network stack without applying any SNAT.
If this is not set autoDirectNodeRoutes will be set
to true
type: string
policyEnforcementMode:
description: PolicyEnforcementMode determines communication
allowed between pods. Accepted values are default, always,
never.
type: string
routingMode:
description: RoutingMode indicates the routing tunnel
mode to use for Cilium. Accepted values are overlay
(geneve tunnel with overlay) or direct (tunneling disabled
with direct routing) Defaults to overlay.
type: string
skipUpgrade:
description: SkipUpgrade indicicates that Cilium maintenance
should be skipped during upgrades. This can be used
when operators wish to self manage the Cilium installation.
type: boolean
type: object
kindnetd:
description: KindnetdConfig contains configuration specific
to the Kindnetd CNI.
type: object
type: object
dns:
Expand Down Expand Up @@ -4388,13 +4415,6 @@ spec:
spec:
description: ControlPlaneUpgradeSpec defines the desired state of ControlPlaneUpgrade.
properties:
cluster:
properties:
kind:
type: string
name:
type: string
type: object
controlPlane:
properties:
kind:
Expand All @@ -4421,13 +4441,15 @@ spec:
type: string
type: object
type: array
upgraderImage:
type: string
required:
- cluster
- controlPlane
- kubeadmClusterConfig
- kubeletVersion
- kubernetesVersion
- machinesRequireUpgrade
- upgraderImage
type: object
status:
description: ControlPlaneUpgradeStatus defines the observed state of ControlPlaneUpgrade.
Expand All @@ -4440,10 +4462,6 @@ spec:
upgraded:
format: int64
type: integer
required:
- ready
- requireUpgrade
- upgraded
type: object
type: object
served: true
Expand Down Expand Up @@ -4823,13 +4841,6 @@ spec:
description: MachineDeploymentUpgradeSpec defines the desired state of
MachineDeploymentUpgrade.
properties:
cluster:
properties:
kind:
type: string
name:
type: string
type: object
kubeadmClusterConfig:
type: string
kubeletVersion:
Expand All @@ -4852,13 +4863,15 @@ spec:
type: string
type: object
type: array
upgraderImage:
type: string
required:
- cluster
- kubeadmClusterConfig
- kubeletVersion
- kubernetesVersion
- machineDeployment
- machinesRequireUpgrade
- upgraderImage
type: object
status:
description: MachineDeploymentUpgradeStatus defines the observed state
Expand Down Expand Up @@ -4969,9 +4982,12 @@ spec:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
upgraderImage:
type: string
required:
- kubernetesVersion
- machine
- upgraderImage
type: object
status:
description: NodeUpgradeStatus defines the observed state of NodeUpgrade.
Expand Down
18 changes: 18 additions & 0 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,21 @@ func validateEksaRelease(ctx context.Context, client client.Client, cluster *any
}
return nil
}

func (r *ClusterReconciler) getUpgraderImagesFromBundle(ctx context.Context, cluster *anywherev1.Cluster) (map[string]string, error) {

Check failure on line 636 in controllers/cluster_controller.go

View workflow job for this annotation

GitHub Actions / lint

func `(*ClusterReconciler).getUpgraderImagesFromBundle` is unused (unused)
upgraderImages := make(map[string]string)
bundles, err := c.BundlesForCluster(ctx, clientutil.NewKubeClient(r.client), cluster)
if err != nil {
return nil, err
}

Check warning on line 641 in controllers/cluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/cluster_controller.go#L636-L641

Added lines #L636 - L641 were not covered by tests

for _, v := range cluster.KubernetesVersions() {
verBundle, err := c.GetVersionsBundle(v, bundles)
if err != nil {
return nil, err
}
upgraderImages[string(v)] = verBundle.Upgrader.Upgrader.URI

Check warning on line 648 in controllers/cluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/cluster_controller.go#L643-L648

Added lines #L643 - L648 were not covered by tests
}

return upgraderImages, nil

Check warning on line 651 in controllers/cluster_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/cluster_controller.go#L651

Added line #L651 was not covered by tests
}
9 changes: 3 additions & 6 deletions controllers/controlplaneupgrade_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func getObjectsForCPUpgradeTest() (*clusterv1.Cluster, []*clusterv1.Machine, []*
machines := []*clusterv1.Machine{machine1, machine2}
nodes := []*corev1.Node{node1, node2}
nodeUpgrades := []*anywherev1.NodeUpgrade{nodeUpgrade1, nodeUpgrade2}
cpUpgrade := generateCPUpgrade(machines, cluster)
cpUpgrade := generateCPUpgrade(machines)
return cluster, machines, nodes, cpUpgrade, nodeUpgrades
}

Expand All @@ -218,18 +218,15 @@ func cpUpgradeRequest(cpUpgrade *anywherev1.ControlPlaneUpgrade) reconcile.Reque
}
}

func generateCPUpgrade(machine []*clusterv1.Machine, cluster *clusterv1.Cluster) *anywherev1.ControlPlaneUpgrade {
func generateCPUpgrade(machine []*clusterv1.Machine) *anywherev1.ControlPlaneUpgrade {
etcdVersion := "v1.28.3-eks-1-28-9"
return &anywherev1.ControlPlaneUpgrade{
ObjectMeta: metav1.ObjectMeta{
Name: "cp-upgrade-request",
Namespace: "eksa-system",
},
Spec: anywherev1.ControlPlaneUpgradeSpec{
Cluster: anywherev1.Ref{
Name: cluster.Name,
Kind: "Cluster",
},
UpgraderImage: "test-image",
ControlPlane: anywherev1.Ref{
Name: "my-cp",
Kind: "KubeadmControlPlane",
Expand Down
9 changes: 3 additions & 6 deletions controllers/machinedeploymentupgrade_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func getObjectsForMDUpgradeTest() (*clusterv1.Cluster, *clusterv1.Machine, *core
node := generateNode()
machine := generateMachine(cluster, node)
nodeUpgrade := generateNodeUpgrade(machine)
mdUpgrade := generateMDUpgrade(machine, cluster)
mdUpgrade := generateMDUpgrade(machine)
return cluster, machine, node, mdUpgrade, nodeUpgrade
}

Expand All @@ -159,17 +159,14 @@ func mdUpgradeRequest(mdUpgrade *anywherev1.MachineDeploymentUpgrade) reconcile.
}
}

func generateMDUpgrade(machine *clusterv1.Machine, cluster *clusterv1.Cluster) *anywherev1.MachineDeploymentUpgrade {
func generateMDUpgrade(machine *clusterv1.Machine) *anywherev1.MachineDeploymentUpgrade {
return &anywherev1.MachineDeploymentUpgrade{
ObjectMeta: metav1.ObjectMeta{
Name: "md-upgrade-request",
Namespace: "eksa-system",
},
Spec: anywherev1.MachineDeploymentUpgradeSpec{
Cluster: anywherev1.Ref{
Name: cluster.Name,
Kind: "Cluster",
},
UpgraderImage: "test-image",
MachineDeployment: anywherev1.Ref{
Name: "my-md",
Kind: "MachineDeployment",
Expand Down
12 changes: 5 additions & 7 deletions controllers/nodeupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import (
)

const (
// TODO(in-place): Get this image from the bundle instead of using the hardcoded one.
defaultUpgraderImage = "public.ecr.aws/t2p4l7v3/upgrader:eksdbase"
controlPlaneLabel = "node-role.kubernetes.io/control-plane"
podDNEMessage = "Upgrader pod does not exist"
controlPlaneLabel = "node-role.kubernetes.io/control-plane"
podDNEMessage = "Upgrader pod does not exist"

// nodeUpgradeFinalizerName is the finalizer added to NodeUpgrade objects to handle deletion.
nodeUpgradeFinalizerName = "nodeupgrades.anywhere.eks.amazonaws.com/finalizer"
Expand Down Expand Up @@ -170,12 +168,12 @@ func (r *NodeUpgradeReconciler) reconcile(ctx context.Context, log logr.Logger,

if isControlPlane(node) {
if nodeUpgrade.Spec.FirstNodeToBeUpgraded {
upgraderPod = upgrader.UpgradeFirstControlPlanePod(node.Name, defaultUpgraderImage, nodeUpgrade.Spec.KubernetesVersion, *nodeUpgrade.Spec.EtcdVersion)
upgraderPod = upgrader.UpgradeFirstControlPlanePod(node.Name, nodeUpgrade.Spec.UpgraderImage, nodeUpgrade.Spec.KubernetesVersion, *nodeUpgrade.Spec.EtcdVersion)
} else {
upgraderPod = upgrader.UpgradeSecondaryControlPlanePod(node.Name, defaultUpgraderImage)
upgraderPod = upgrader.UpgradeSecondaryControlPlanePod(node.Name, nodeUpgrade.Spec.UpgraderImage)
}
} else {
upgraderPod = upgrader.UpgradeWorkerPod(node.Name, defaultUpgraderImage)
upgraderPod = upgrader.UpgradeWorkerPod(node.Name, nodeUpgrade.Spec.UpgraderImage)
}

if err := remoteClient.Create(ctx, upgraderPod); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1alpha1/controlplaneupgrade_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ControlPlaneUpgradeKind = "ControlPlaneUpgrade"

// ControlPlaneUpgradeSpec defines the desired state of ControlPlaneUpgrade.
type ControlPlaneUpgradeSpec struct {
Cluster Ref `json:"cluster"`
UpgraderImage string `json:"upgraderImage"`
ControlPlane Ref `json:"controlPlane"`
MachinesRequireUpgrade []Ref `json:"machinesRequireUpgrade"`
KubernetesVersion string `json:"kubernetesVersion"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1alpha1/machinedeploymentupgrade_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MachineDeploymentUpgradeKind = "MachineDeploymentUpgrade"

// MachineDeploymentUpgradeSpec defines the desired state of MachineDeploymentUpgrade.
type MachineDeploymentUpgradeSpec struct {
Cluster Ref `json:"cluster"`
UpgraderImage string `json:"upgraderImage"`
MachineDeployment Ref `json:"machineDeployment"`
MachinesRequireUpgrade []Ref `json:"machinesRequireUpgrade"`
KubernetesVersion string `json:"kubernetesVersion"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1alpha1/nodeupgrade_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type NodeUpgradeSpec struct {
// This flag is only valid for control plane nodes and ignored for worker nodes.
// +optional
FirstNodeToBeUpgraded bool `json:"firstNodeToBeUpgraded,omitempty"`

UpgraderImage string `json:"upgraderImage"`
}

// NodeUpgradeStatus defines the observed state of NodeUpgrade.
Expand Down
2 changes: 0 additions & 2 deletions pkg/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 57c6084

Please sign in to comment.