Skip to content

Commit

Permalink
Merge branch 'update-remove-node-taints' into 'main'
Browse files Browse the repository at this point in the history
update(taints): remove node tainting

Closes CN-2689

See merge request cloudnative/go/cidr-allocator!21
  • Loading branch information
Ben Sykes committed Feb 29, 2024
2 parents f773365 + 976bc0a commit 85bbac1
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 216 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.2.0] - 2024-02-29
### Removed
- update(taints): removed Node tainting as not necessary

## [v1.1.1] - 2024-02-26
### Fixed
- fix(taints): fixed issue where Node taint was being applied irrespective of whether it was already applied
Expand Down
4 changes: 2 additions & 2 deletions install/kubernetes/cidr-allocator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ keywords:
- Networking
- Node

version: 2.0.4
version: 2.0.5
kubeVersion: ">= 1.16.0-0"
appVersion: "v1.1.1"
appVersion: "v1.2.0"

maintainers:
- name: Ben Sykes
Expand Down
2 changes: 1 addition & 1 deletion install/kubernetes/cidr-allocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A Helm chart to deploy the STATCAN CIDR-Allocator Controller and CRDs to a Kubernetes Cluster

![Version: 2.0.4](https://img.shields.io/badge/Version-2.0.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v1.1.1](https://img.shields.io/badge/AppVersion-v1.1.1-informational?style=flat-square)
![Version: 2.0.5](https://img.shields.io/badge/Version-2.0.5-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v1.2.0](https://img.shields.io/badge/AppVersion-v1.2.0-informational?style=flat-square)

A Helm chart to deploy the STATCAN CIDR-Allocator Controller and CRDs to a Kubernetes Cluster

Expand Down
40 changes: 0 additions & 40 deletions internal/controller/nodecidrallocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controller

import (
"context"
"errors"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -42,21 +41,12 @@ import (
"statcan.gc.ca/cidr-allocator/internal/helper"
statcan_metrics "statcan.gc.ca/cidr-allocator/internal/metrics"
statcan_net "statcan.gc.ca/cidr-allocator/internal/networking"
"statcan.gc.ca/cidr-allocator/internal/taint"
)

const (
finalizerName = "nodecidrallocation.networking.statcan.gc.ca/finalizer"
)

var (
nodeTaint = corev1.Taint{
Key: "node.networking.statcan.gc.ca/network-unavailable",
Value: "true",
Effect: corev1.TaintEffectNoSchedule,
}
)

// NodeCIDRAllocationReconciler reconciles a NodeCIDRAllocation object
type NodeCIDRAllocationReconciler struct {
client.Client
Expand Down Expand Up @@ -335,9 +325,6 @@ func (r *NodeCIDRAllocationReconciler) finalizeReconcile(ctx context.Context, no
r.updateNodeCIDRAllocationStatus(ctx, nodeCIDRAllocation, nodes, err)
r.updatePrometheusMetrics(ctx)

// remove or add Node taints according to allocation status of each matching node
err = errors.Join(err, r.updateNodeTaints(ctx, nodes))

// passthrough for err (if non-nil) to the Reconcile Result
return err
}
Expand Down Expand Up @@ -399,33 +386,6 @@ func (r *NodeCIDRAllocationReconciler) updateNodeCIDRAllocationStatus(ctx contex
}
}

func (r *NodeCIDRAllocationReconciler) updateNodeTaints(ctx context.Context, nodes *corev1.NodeList) error {
ntc := taint.New()
for _, node := range nodes.Items {
// does not have an assigned PodCIDR - taint the Node
if node.Spec.PodCIDR == "" && !ntc.HasTaint(&node, nodeTaint.Key) {
ntc.AddNodeTaint(&node, nodeTaint)
}

// has a PodCIDR assigned - remove the taint from the Node
if node.Spec.PodCIDR != "" && ntc.HasTaint(&node, nodeTaint.Key) {
ntc.RemoveNodeTaint(&node, nodeTaint.Key)
}

if err := r.Client.Update(ctx, &node); err != nil {
if apierrors.IsNotFound(err) {
// node was removed after reconcile request was created - skip the Node
continue
}

// error trying to add the Node taint to the Node object
return err
}
}

return nil
}

// triggerNodeCIDRAllocationReconcileFromNodeChange is a mapping function which takes a Node object
// and returns a list of reconciliation requests for all NodeCIDRAllocation resources that have a matching NodeSelector
func (r *NodeCIDRAllocationReconciler) triggerNodeCIDRAllocationReconcileFromNodeChange(ctx context.Context, o client.Object) []reconcile.Request {
Expand Down
76 changes: 0 additions & 76 deletions internal/taint/taint.go

This file was deleted.

97 changes: 0 additions & 97 deletions internal/taint/taint_test.go

This file was deleted.

0 comments on commit 85bbac1

Please sign in to comment.