Skip to content

Commit

Permalink
Fix tinkerbell IP in hegel urls controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude committed Feb 14, 2024
1 parent f97684d commit bc74b75
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/api/v1alpha1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,29 @@ func (c *Cluster) ClearManagedByCLIAnnotation() {
}
}

// AddTinkerbellIPAnnotation adds the managed-by-cli annotation to the cluster.
func (c *Cluster) AddTinkerbellIPAnnotation(tinkerbellIP string) {
if c.Annotations == nil {
c.Annotations = map[string]string{}

Check warning on line 317 in pkg/api/v1alpha1/cluster.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/cluster.go#L315-L317

Added lines #L315 - L317 were not covered by tests
}
c.Annotations[tinkerbellIPAnnotation] = tinkerbellIP

Check warning on line 319 in pkg/api/v1alpha1/cluster.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/cluster.go#L319

Added line #L319 was not covered by tests
}

// ClearTinkerbellIPAnnotation removes the managed-by-cli annotation from the cluster.
func (c *Cluster) ClearTinkerbellIPAnnotation() {
if c.Annotations != nil {
delete(c.Annotations, tinkerbellIPAnnotation)

Check warning on line 325 in pkg/api/v1alpha1/cluster.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/cluster.go#L323-L325

Added lines #L323 - L325 were not covered by tests
}
}

// HasTinkerbellIPAnnotation returns the tinkerbell IP value if the annotation exists.
func (c *Cluster) HasTinkerbellIPAnnotation() (string, bool) {
if tinkerbellIP, ok := c.Annotations[tinkerbellIPAnnotation]; ok {
return tinkerbellIP, true

Check warning on line 332 in pkg/api/v1alpha1/cluster.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/cluster.go#L330-L332

Added lines #L330 - L332 were not covered by tests
}
return "", false

Check warning on line 334 in pkg/api/v1alpha1/cluster.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/cluster.go#L334

Added line #L334 was not covered by tests
}

// RegistryAuth returns whether registry requires authentication or not.
func (c *Cluster) RegistryAuth() bool {
if c.Spec.RegistryMirrorConfiguration == nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const (
// the controller will remove the finalizer and let the cluster be deleted.
ManagedByCLIAnnotation = "anywhere.eks.amazonaws.com/managed-by-cli"

// tinkerbellIPAnnotation can be applied to an EKS-A Cluster to convey the tinkerbell bootstrap ip to the
// EKSA controller. When marked for deletion, the controller will remove the IP annotation.
tinkerbellIPAnnotation = "anywhere.eks.amazonaws.com/tinkerbell-bootstrap-ip"

// ControlPlaneAnnotation is an annotation that can be applied to EKS-A machineconfig
// object to prevent a controller from making changes to that resource.
controlPlaneAnnotation = "anywhere.eks.amazonaws.com/control-plane"
Expand Down
2 changes: 2 additions & 0 deletions pkg/providers/tinkerbell/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (p *Provider) BootstrapClusterOpts(_ *cluster.Spec) ([]bootstrapper.Bootstr
func (p *Provider) PreCAPIInstallOnBootstrap(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error {
logger.V(4).Info("Installing Tinkerbell stack on bootstrap cluster")

logger.V(4).Info("Adding annotation for tinkerbell ip on bootstrap cluster")
clusterSpec.Cluster.AddTinkerbellIPAnnotation(p.tinkerbellIP)
versionsBundle := clusterSpec.RootVersionsBundle()

err := p.stackInstaller.Install(
Expand Down
8 changes: 8 additions & 0 deletions pkg/providers/tinkerbell/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (tb *TemplateBuilder) GenerateCAPISpecControlPlane(clusterSpec *cluster.Spe
}
var OSImageURL string

if tinkerbellIP, ok := clusterSpec.Cluster.HasTinkerbellIPAnnotation(); ok {
tb.tinkerbellIP = tinkerbellIP

Check warning on line 75 in pkg/providers/tinkerbell/template.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/tinkerbell/template.go#L75

Added line #L75 was not covered by tests
}

if cpTemplateConfig == nil {
OSImageURL = clusterSpec.TinkerbellDatacenter.Spec.OSImageURL
if tb.controlPlaneMachineSpec.OSImageURL != "" {
Expand Down Expand Up @@ -123,6 +127,10 @@ func (tb *TemplateBuilder) GenerateCAPISpecWorkers(clusterSpec *cluster.Spec, wo
bundle := clusterSpec.RootVersionsBundle()
OSImageURL := clusterSpec.TinkerbellDatacenter.Spec.OSImageURL

if tinkerbellIP, ok := clusterSpec.Cluster.HasTinkerbellIPAnnotation(); ok {
tb.tinkerbellIP = tinkerbellIP

Check warning on line 131 in pkg/providers/tinkerbell/template.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/tinkerbell/template.go#L131

Added line #L131 was not covered by tests
}

for _, workerNodeGroupConfiguration := range clusterSpec.Cluster.Spec.WorkerNodeGroupConfigurations {
workerNodeMachineSpec := tb.WorkerNodeGroupMachineSpecs[workerNodeGroupConfiguration.MachineGroupRef.Name]
wTemplateConfig := clusterSpec.TinkerbellTemplateConfigs[workerNodeMachineSpec.TemplateRef.Name]
Expand Down
6 changes: 6 additions & 0 deletions pkg/workflows/management/create_install_eksa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package management
import (
"context"

"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/task"
Expand Down Expand Up @@ -38,6 +39,11 @@ func (s *installEksaComponentsOnBootstrapTask) Checkpoint() *task.CompletedTask
type installEksaComponentsOnWorkloadTask struct{}

func (s *installEksaComponentsOnWorkloadTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task {
if commandContext.ClusterSpec.Cluster.Spec.DatacenterRef.Kind == v1alpha1.TinkerbellDatacenterKind {
logger.Info("Removing Tinkerbell IP annotation")
commandContext.ClusterSpec.Cluster.ClearTinkerbellIPAnnotation()

Check warning on line 44 in pkg/workflows/management/create_install_eksa.go

View check run for this annotation

Codecov / codecov/patch

pkg/workflows/management/create_install_eksa.go#L43-L44

Added lines #L43 - L44 were not covered by tests
}

logger.Info("Installing EKS-A custom components on workload cluster")

err := installEKSAComponents(ctx, commandContext, commandContext.WorkloadCluster)
Expand Down

0 comments on commit bc74b75

Please sign in to comment.