From 36460df246cffb4cb3da099d03a04e29f25cf17c Mon Sep 17 00:00:00 2001 From: Marwan Ahmed Date: Sun, 6 Jun 2021 13:16:14 -0700 Subject: [PATCH 1/2] annotate fakeNodes so that cloudprovider implementations can identify them if needed --- cluster-autoscaler/clusterstate/clusterstate.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cluster-autoscaler/clusterstate/clusterstate.go b/cluster-autoscaler/clusterstate/clusterstate.go index e66d49636808..6bc9703f650b 100644 --- a/cluster-autoscaler/clusterstate/clusterstate.go +++ b/cluster-autoscaler/clusterstate/clusterstate.go @@ -51,6 +51,14 @@ const ( // NodeGroupBackoffResetTimeout is the time after last failed scale-up when the backoff duration is reset. NodeGroupBackoffResetTimeout = 3 * time.Hour + + // FakeNodeReasonAnnotation is an annotation added to the fake placeholder nodes CA has created + // Note that this don't map to real nodes in k8s and are merely used for error handling + FakeNodeReasonAnnotation = "k8s.io/cluster-autoscaler/fake-node-reason" + // FakeNodeUnregistered represents a node that is identified by CA as unregistered + FakeNodeUnregistered = "unregistered" + // FakeNodeCreateError represents a node that is identified by CA as a created node with errors + FakeNodeCreateError = "create-error" ) // ScaleUpRequest contains information about the requested node group scale up. @@ -949,7 +957,7 @@ func getNotRegisteredNodes(allNodes []*apiv1.Node, cloudProviderNodeInstances ma for _, instance := range instances { if !registered.Has(instance.Id) { notRegistered = append(notRegistered, UnregisteredNode{ - Node: fakeNode(instance), + Node: fakeNode(instance, FakeNodeUnregistered), UnregisteredSince: time, }) } @@ -1096,7 +1104,7 @@ func (csr *ClusterStateRegistry) GetCreatedNodesWithErrors() []*apiv1.Node { _, _, instancesByErrorCode := csr.buildInstanceToErrorCodeMappings(nodeGroupInstances) for _, instances := range instancesByErrorCode { for _, instance := range instances { - nodesWithCreateErrors = append(nodesWithCreateErrors, fakeNode(instance)) + nodesWithCreateErrors = append(nodesWithCreateErrors, fakeNode(instance, FakeNodeCreateError)) } } } @@ -1113,10 +1121,13 @@ func (csr *ClusterStateRegistry) InvalidateNodeInstancesCacheEntry(nodeGroup clo csr.cloudProviderNodeInstancesCache.InvalidateCacheEntry(nodeGroup) } -func fakeNode(instance cloudprovider.Instance) *apiv1.Node { +func fakeNode(instance cloudprovider.Instance, reason string) *apiv1.Node { return &apiv1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: instance.Id, + Annotations: map[string]string{ + FakeNodeReasonAnnotation: reason, + }, }, Spec: apiv1.NodeSpec{ ProviderID: instance.Id, From 8039af647e2f46328c81f11b1d2413172500188c Mon Sep 17 00:00:00 2001 From: Marwan Ahmed Date: Tue, 8 Jun 2021 10:56:35 -0700 Subject: [PATCH 2/2] move annotations to cloudprovider package --- cluster-autoscaler/cloudprovider/cloud_provider.go | 10 ++++++++++ cluster-autoscaler/clusterstate/clusterstate.go | 14 +++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/cloud_provider.go b/cluster-autoscaler/cloudprovider/cloud_provider.go index c53937da2e78..41ec7e914903 100644 --- a/cluster-autoscaler/cloudprovider/cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/cloud_provider.go @@ -256,6 +256,16 @@ func (c InstanceErrorClass) String() string { } } +const ( + // FakeNodeReasonAnnotation is an annotation added to the fake placeholder nodes CA has created + // Note that this don't map to real nodes in k8s and are merely used for error handling + FakeNodeReasonAnnotation = "k8s.io/cluster-autoscaler/fake-node-reason" + // FakeNodeUnregistered represents a node that is identified by CA as unregistered + FakeNodeUnregistered = "unregistered" + // FakeNodeCreateError represents a node that is identified by CA as a created node with errors + FakeNodeCreateError = "create-error" +) + // PricingModel contains information about the node price and how it changes in time. type PricingModel interface { // NodePrice returns a price of running the given node for a given period of time. diff --git a/cluster-autoscaler/clusterstate/clusterstate.go b/cluster-autoscaler/clusterstate/clusterstate.go index 6bc9703f650b..7eaa2ce330a4 100644 --- a/cluster-autoscaler/clusterstate/clusterstate.go +++ b/cluster-autoscaler/clusterstate/clusterstate.go @@ -51,14 +51,6 @@ const ( // NodeGroupBackoffResetTimeout is the time after last failed scale-up when the backoff duration is reset. NodeGroupBackoffResetTimeout = 3 * time.Hour - - // FakeNodeReasonAnnotation is an annotation added to the fake placeholder nodes CA has created - // Note that this don't map to real nodes in k8s and are merely used for error handling - FakeNodeReasonAnnotation = "k8s.io/cluster-autoscaler/fake-node-reason" - // FakeNodeUnregistered represents a node that is identified by CA as unregistered - FakeNodeUnregistered = "unregistered" - // FakeNodeCreateError represents a node that is identified by CA as a created node with errors - FakeNodeCreateError = "create-error" ) // ScaleUpRequest contains information about the requested node group scale up. @@ -957,7 +949,7 @@ func getNotRegisteredNodes(allNodes []*apiv1.Node, cloudProviderNodeInstances ma for _, instance := range instances { if !registered.Has(instance.Id) { notRegistered = append(notRegistered, UnregisteredNode{ - Node: fakeNode(instance, FakeNodeUnregistered), + Node: fakeNode(instance, cloudprovider.FakeNodeUnregistered), UnregisteredSince: time, }) } @@ -1104,7 +1096,7 @@ func (csr *ClusterStateRegistry) GetCreatedNodesWithErrors() []*apiv1.Node { _, _, instancesByErrorCode := csr.buildInstanceToErrorCodeMappings(nodeGroupInstances) for _, instances := range instancesByErrorCode { for _, instance := range instances { - nodesWithCreateErrors = append(nodesWithCreateErrors, fakeNode(instance, FakeNodeCreateError)) + nodesWithCreateErrors = append(nodesWithCreateErrors, fakeNode(instance, cloudprovider.FakeNodeCreateError)) } } } @@ -1126,7 +1118,7 @@ func fakeNode(instance cloudprovider.Instance, reason string) *apiv1.Node { ObjectMeta: metav1.ObjectMeta{ Name: instance.Id, Annotations: map[string]string{ - FakeNodeReasonAnnotation: reason, + cloudprovider.FakeNodeReasonAnnotation: reason, }, }, Spec: apiv1.NodeSpec{