mirror of https://github.com/kubernetes/kops.git
Rename NodeReconciler to LegacyNodeReconciler
This commit is contained in:
parent
0a428bebf8
commit
24ff622d8e
|
|
@ -2,7 +2,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
|||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["node_controller.go"],
|
||||
srcs = ["legacy_node_controller.go"],
|
||||
importpath = "k8s.io/kops/cmd/kops-controller/controllers",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/manager"
|
||||
)
|
||||
|
||||
// NewNodeReconciler is the constructor for a NodeReconciler
|
||||
func NewNodeReconciler(mgr manager.Manager, configPath string, identifier nodeidentity.Identifier) (*NodeReconciler, error) {
|
||||
r := &NodeReconciler{
|
||||
// NewLegacyNodeReconciler is the constructor for a LegacyNodeReconciler
|
||||
func NewLegacyNodeReconciler(mgr manager.Manager, configPath string, identifier nodeidentity.LegacyIdentifier) (*LegacyNodeReconciler, error) {
|
||||
r := &LegacyNodeReconciler{
|
||||
client: mgr.GetClient(),
|
||||
log: ctrl.Log.WithName("controllers").WithName("Node"),
|
||||
identifier: identifier,
|
||||
|
|
@ -64,9 +64,9 @@ func NewNodeReconciler(mgr manager.Manager, configPath string, identifier nodeid
|
|||
return r, nil
|
||||
}
|
||||
|
||||
// NodeReconciler observes Node objects, and labels them with the correct labels for the instancegroup
|
||||
// LegacyNodeReconciler observes Node objects, and labels them with the correct labels for the instancegroup
|
||||
// This used to be done by the kubelet, but is moving to a central controller for greater security in 1.16
|
||||
type NodeReconciler struct {
|
||||
type LegacyNodeReconciler struct {
|
||||
// client is the controller-runtime client
|
||||
client client.Client
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ type NodeReconciler struct {
|
|||
coreV1Client *corev1client.CoreV1Client
|
||||
|
||||
// identifier is a provider that can securely map node ProviderIDs to InstanceGroups
|
||||
identifier nodeidentity.Identifier
|
||||
identifier nodeidentity.LegacyIdentifier
|
||||
|
||||
// configBase is the parsed path to the base location of our configuration files
|
||||
configBase vfs.Path
|
||||
|
|
@ -88,7 +88,7 @@ type NodeReconciler struct {
|
|||
|
||||
// +kubebuilder:rbac:groups=,resources=nodes,verbs=get;list;watch;patch
|
||||
// Reconciler is the main reconciler function that observes node changes
|
||||
func (r *NodeReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
func (r *LegacyNodeReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
ctx := context.Background()
|
||||
_ = r.log.WithValues("nodecontroller", req.NamespacedName)
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ func (r *NodeReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
|||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
func (r *NodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
func (r *LegacyNodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&corev1.Node{}).
|
||||
Complete(r)
|
||||
|
|
@ -161,7 +161,7 @@ type nodePatchMetadata struct {
|
|||
}
|
||||
|
||||
// patchNodeLabels patches the node labels to set the specified labels
|
||||
func (r *NodeReconciler) patchNodeLabels(ctx context.Context, node *corev1.Node, setLabels map[string]string) error {
|
||||
func (r *LegacyNodeReconciler) patchNodeLabels(ctx context.Context, node *corev1.Node, setLabels map[string]string) error {
|
||||
nodePatchMetadata := &nodePatchMetadata{
|
||||
Labels: setLabels,
|
||||
}
|
||||
|
|
@ -185,7 +185,7 @@ func (r *NodeReconciler) patchNodeLabels(ctx context.Context, node *corev1.Node,
|
|||
|
||||
// getClusterForNode returns the kops.Cluster object for the node
|
||||
// The cluster is actually loaded when we first start
|
||||
func (r *NodeReconciler) getClusterForNode(node *corev1.Node) (*kops.Cluster, error) {
|
||||
func (r *LegacyNodeReconciler) getClusterForNode(node *corev1.Node) (*kops.Cluster, error) {
|
||||
clusterPath := r.configBase.Join(registry.PathClusterCompleted)
|
||||
cluster, err := r.loadCluster(clusterPath)
|
||||
if err != nil {
|
||||
|
|
@ -195,7 +195,7 @@ func (r *NodeReconciler) getClusterForNode(node *corev1.Node) (*kops.Cluster, er
|
|||
}
|
||||
|
||||
// getInstanceLifecycle returns InstanceLifecycle string object
|
||||
func (r *NodeReconciler) getInstanceLifecycle(ctx context.Context, node *corev1.Node) (string, error) {
|
||||
func (r *LegacyNodeReconciler) getInstanceLifecycle(ctx context.Context, node *corev1.Node) (string, error) {
|
||||
|
||||
identity, err := r.identifier.IdentifyNode(ctx, node)
|
||||
if err != nil {
|
||||
|
|
@ -206,7 +206,7 @@ func (r *NodeReconciler) getInstanceLifecycle(ctx context.Context, node *corev1.
|
|||
}
|
||||
|
||||
// getInstanceGroupForNode returns the kops.InstanceGroup object for the node
|
||||
func (r *NodeReconciler) getInstanceGroupForNode(ctx context.Context, node *corev1.Node) (*kops.InstanceGroup, error) {
|
||||
func (r *LegacyNodeReconciler) getInstanceGroupForNode(ctx context.Context, node *corev1.Node) (*kops.InstanceGroup, error) {
|
||||
// We assume that if the instancegroup label is set, that it is correct
|
||||
// TODO: Should we be paranoid?
|
||||
instanceGroupName := node.Labels["kops.k8s.io/instancegroup"]
|
||||
|
|
@ -232,7 +232,7 @@ func (r *NodeReconciler) getInstanceGroupForNode(ctx context.Context, node *core
|
|||
}
|
||||
|
||||
// loadCluster loads a kops.Cluster object from a vfs.Path
|
||||
func (r *NodeReconciler) loadCluster(p vfs.Path) (*kops.Cluster, error) {
|
||||
func (r *LegacyNodeReconciler) loadCluster(p vfs.Path) (*kops.Cluster, error) {
|
||||
ttl := time.Hour
|
||||
|
||||
b, err := r.cache.Read(p, ttl)
|
||||
|
|
@ -249,7 +249,7 @@ func (r *NodeReconciler) loadCluster(p vfs.Path) (*kops.Cluster, error) {
|
|||
}
|
||||
|
||||
// loadInstanceGroup loads a kops.InstanceGroup object from the vfs backing store
|
||||
func (r *NodeReconciler) loadNamedInstanceGroup(name string) (*kops.InstanceGroup, error) {
|
||||
func (r *LegacyNodeReconciler) loadNamedInstanceGroup(name string) (*kops.InstanceGroup, error) {
|
||||
p := r.configBase.Join("instancegroup", name)
|
||||
|
||||
ttl := time.Hour
|
||||
|
|
@ -146,7 +146,7 @@ func buildScheme() error {
|
|||
}
|
||||
|
||||
func addNodeController(mgr manager.Manager, opt *config.Options) error {
|
||||
var identifier nodeidentity.Identifier
|
||||
var identifier nodeidentity.LegacyIdentifier
|
||||
var err error
|
||||
switch opt.Cloud {
|
||||
case "aws":
|
||||
|
|
@ -183,7 +183,7 @@ func addNodeController(mgr manager.Manager, opt *config.Options) error {
|
|||
return fmt.Errorf("must specify configBase")
|
||||
}
|
||||
|
||||
nodeController, err := controllers.NewNodeReconciler(mgr, opt.ConfigBase, identifier)
|
||||
nodeController, err := controllers.NewLegacyNodeReconciler(mgr, opt.ConfigBase, identifier)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ type nodeIdentifier struct {
|
|||
}
|
||||
|
||||
// New creates and returns a nodeidentity.Identifier for Nodes running on AWS
|
||||
func New(CacheNodeidentityInfo bool) (nodeidentity.Identifier, error) {
|
||||
func New(CacheNodeidentityInfo bool) (nodeidentity.LegacyIdentifier, error) {
|
||||
config := aws.NewConfig()
|
||||
config = config.WithCredentialsChainVerboseErrors(true)
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ func stringKeyFunc(obj interface{}) (string, error) {
|
|||
}
|
||||
|
||||
// IdentifyNode queries AWS for the node identity information
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.Info, error) {
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.LegacyInfo, error) {
|
||||
providerID := node.Spec.ProviderID
|
||||
if providerID == "" {
|
||||
return nil, fmt.Errorf("providerID was not set for node %s", node.Name)
|
||||
|
|
@ -145,7 +145,7 @@ func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*
|
|||
return nil, fmt.Errorf("%s tag not set on instance %s", CloudTagInstanceGroupName, aws.StringValue(instance.InstanceId))
|
||||
}
|
||||
|
||||
info := &nodeidentity.Info{}
|
||||
info := &nodeidentity.LegacyInfo{}
|
||||
info.InstanceID = instanceID
|
||||
info.InstanceGroup = igName
|
||||
info.InstanceLifecycle = lifecycle
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ func (t *TokenSource) Token() (*oauth2.Token, error) {
|
|||
return token, nil
|
||||
}
|
||||
|
||||
// New creates and returns a nodeidentity.Identifier for Nodes running on DO
|
||||
func New() (nodeidentity.Identifier, error) {
|
||||
// New creates and returns a nodeidentity.LegacyIdentifier for Nodes running on DO
|
||||
func New() (nodeidentity.LegacyIdentifier, error) {
|
||||
region, err := getMetadataRegion()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get droplet region: %s", err)
|
||||
|
|
@ -116,7 +116,7 @@ func getMetadata(url string) (string, error) {
|
|||
}
|
||||
|
||||
// IdentifyNode queries DO for the node identity information
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.Info, error) {
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.LegacyInfo, error) {
|
||||
providerID := node.Spec.ProviderID
|
||||
|
||||
if providerID == "" {
|
||||
|
|
@ -144,7 +144,7 @@ func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := &nodeidentity.Info{}
|
||||
info := &nodeidentity.LegacyInfo{}
|
||||
info.InstanceGroup = kopsGroup
|
||||
|
||||
return info, nil
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ type nodeIdentifier struct {
|
|||
project string
|
||||
}
|
||||
|
||||
// New creates and returns a nodeidentity.Identifier for Nodes running on GCE
|
||||
func New() (nodeidentity.Identifier, error) {
|
||||
// New creates and returns a nodeidentity.LegacyIdentifier for Nodes running on GCE
|
||||
func New() (nodeidentity.LegacyIdentifier, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
computeService, err := compute.NewService(ctx)
|
||||
|
|
@ -75,7 +75,7 @@ func New() (nodeidentity.Identifier, error) {
|
|||
}
|
||||
|
||||
// IdentifyNode queries GCE for the node identity information
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.Info, error) {
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.LegacyInfo, error) {
|
||||
providerID := node.Spec.ProviderID
|
||||
if providerID == "" {
|
||||
return nil, fmt.Errorf("providerID was not set for node %s", node.Name)
|
||||
|
|
@ -143,7 +143,7 @@ func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*
|
|||
return nil, fmt.Errorf("ig name not set on instance template %s", instanceTemplate.Name)
|
||||
}
|
||||
|
||||
info := &nodeidentity.Info{}
|
||||
info := &nodeidentity.LegacyInfo{}
|
||||
info.InstanceGroup = igName
|
||||
return info, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ import (
|
|||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type Identifier interface {
|
||||
IdentifyNode(ctx context.Context, node *corev1.Node) (*Info, error)
|
||||
type LegacyIdentifier interface {
|
||||
IdentifyNode(ctx context.Context, node *corev1.Node) (*LegacyInfo, error)
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
type LegacyInfo struct {
|
||||
InstanceID string
|
||||
InstanceGroup string
|
||||
InstanceLifecycle string
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ type nodeIdentifier struct {
|
|||
novaClient *gophercloud.ServiceClient
|
||||
}
|
||||
|
||||
// New creates and returns a nodeidentity.Identifier for Nodes running on OpenStack
|
||||
func New() (nodeidentity.Identifier, error) {
|
||||
// New creates and returns a nodeidentity.LegacyIdentifier for Nodes running on OpenStack
|
||||
func New() (nodeidentity.LegacyIdentifier, error) {
|
||||
env, err := openstack.AuthOptionsFromEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -73,7 +73,7 @@ func New() (nodeidentity.Identifier, error) {
|
|||
}
|
||||
|
||||
// IdentifyNode queries OpenStack for the node identity information
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.Info, error) {
|
||||
func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.LegacyInfo, error) {
|
||||
providerID := node.Spec.ProviderID
|
||||
if providerID == "" {
|
||||
return nil, fmt.Errorf("providerID was not set for node %s", node.Name)
|
||||
|
|
@ -94,7 +94,7 @@ func (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := &nodeidentity.Info{}
|
||||
info := &nodeidentity.LegacyInfo{}
|
||||
info.InstanceGroup = kopsGroup
|
||||
|
||||
return info, nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue