-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Finalize migration to contextual logging from cluster-autoscaler repo. #10164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ limitations under the License. | |
| package alicloud | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| apiv1 "k8s.io/api/core/v1" | ||
|
|
@@ -36,24 +37,24 @@ type Asg struct { | |
| } | ||
|
|
||
| // MaxSize returns maximum size of the node group. | ||
| func (asg *Asg) MaxSize() int { | ||
| func (asg *Asg) MaxSize(ctx context.Context) int { | ||
| return asg.maxSize | ||
| } | ||
|
|
||
| // MinSize returns minimum size of the node group. | ||
| func (asg *Asg) MinSize() int { | ||
| func (asg *Asg) MinSize(ctx context.Context) int { | ||
| return asg.minSize | ||
| } | ||
|
|
||
| // TargetSize returns the current TARGET size of the node group. It is possible that the | ||
| // number is different from the number of nodes registered in Kubernetes. | ||
| func (asg *Asg) TargetSize() (int, error) { | ||
| func (asg *Asg) TargetSize(ctx context.Context) (int, error) { | ||
| size, err := asg.manager.GetAsgSize(asg) | ||
| return int(size), err | ||
| } | ||
|
|
||
| // IncreaseSize increases Asg size | ||
| func (asg *Asg) IncreaseSize(delta int) error { | ||
| func (asg *Asg) IncreaseSize(ctx context.Context, delta int) error { | ||
| klog.Infof("increase ASG:%s with %d nodes", asg.Id(), delta) | ||
| if delta <= 0 { | ||
| return fmt.Errorf("size increase must be positive") | ||
|
|
@@ -63,14 +64,14 @@ func (asg *Asg) IncreaseSize(delta int) error { | |
| klog.Errorf("failed to get ASG size because of %s", err.Error()) | ||
| return err | ||
| } | ||
| if int(size)+delta > asg.MaxSize() { | ||
| return fmt.Errorf("size increase is too large - desired:%d max:%d", int(size)+delta, asg.MaxSize()) | ||
| if int(size)+delta > asg.MaxSize(context.TODO()) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as for the PR in core CA - why not just propagate |
||
| return fmt.Errorf("size increase is too large - desired:%d max:%d", int(size)+delta, asg.MaxSize(context.TODO())) | ||
| } | ||
| return asg.manager.SetAsgSize(asg, size+int64(delta)) | ||
| } | ||
|
|
||
| // AtomicIncreaseSize is not implemented. | ||
| func (asg *Asg) AtomicIncreaseSize(delta int) error { | ||
| func (asg *Asg) AtomicIncreaseSize(ctx context.Context, delta int) error { | ||
| return cloudprovider.ErrNotImplemented | ||
| } | ||
|
|
||
|
|
@@ -79,7 +80,7 @@ func (asg *Asg) AtomicIncreaseSize(delta int) error { | |
| // request for new nodes that have not been yet fulfilled. Delta should be negative. | ||
| // It is assumed that cloud provider will not delete the existing nodes if the size | ||
| // when there is an option to just decrease the target. | ||
| func (asg *Asg) DecreaseTargetSize(delta int) error { | ||
| func (asg *Asg) DecreaseTargetSize(ctx context.Context, delta int) error { | ||
| klog.V(4).Infof("Aliyun: DecreaseTargetSize() with args: %v", delta) | ||
| if delta >= 0 { | ||
| return fmt.Errorf("size decrease size must be negative") | ||
|
|
@@ -121,13 +122,13 @@ func (asg *Asg) Belongs(node *apiv1.Node) (bool, error) { | |
| } | ||
|
|
||
| // DeleteNodes deletes the nodes from the group. | ||
| func (asg *Asg) DeleteNodes(nodes []*apiv1.Node) error { | ||
| func (asg *Asg) DeleteNodes(ctx context.Context, nodes []*apiv1.Node) error { | ||
| size, err := asg.manager.GetAsgSize(asg) | ||
| if err != nil { | ||
| klog.Errorf("failed to get ASG size because of %s", err.Error()) | ||
| return err | ||
| } | ||
| if int(size) <= asg.MinSize() { | ||
| if int(size) <= asg.MinSize(context.TODO()) { | ||
| return fmt.Errorf("min size reached, nodes will not be deleted") | ||
| } | ||
| nodeIds := make([]string, 0, len(nodes)) | ||
|
|
@@ -151,7 +152,7 @@ func (asg *Asg) DeleteNodes(nodes []*apiv1.Node) error { | |
| } | ||
|
|
||
| // ForceDeleteNodes deletes nodes from the group regardless of constraints. | ||
| func (asg *Asg) ForceDeleteNodes(nodes []*apiv1.Node) error { | ||
| func (asg *Asg) ForceDeleteNodes(ctx context.Context, nodes []*apiv1.Node) error { | ||
| return cloudprovider.ErrNotImplemented | ||
| } | ||
|
|
||
|
|
@@ -166,12 +167,12 @@ func (asg *Asg) RegionId() string { | |
| } | ||
|
|
||
| // Debug returns a debug string for the Asg. | ||
| func (asg *Asg) Debug() string { | ||
| return fmt.Sprintf("%s (%d:%d)", asg.Id(), asg.MinSize(), asg.MaxSize()) | ||
| func (asg *Asg) Debug(ctx context.Context) string { | ||
| return fmt.Sprintf("%s (%d:%d)", asg.Id(), asg.MinSize(context.TODO()), asg.MaxSize(context.TODO())) | ||
| } | ||
|
|
||
| // Nodes returns a list of all nodes that belong to this node group. | ||
| func (asg *Asg) Nodes() ([]cloudprovider.Instance, error) { | ||
| func (asg *Asg) Nodes(ctx context.Context) ([]cloudprovider.Instance, error) { | ||
| instanceNames, err := asg.manager.GetAsgNodes(asg) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -184,7 +185,7 @@ func (asg *Asg) Nodes() ([]cloudprovider.Instance, error) { | |
| } | ||
|
|
||
| // TemplateNodeInfo returns a node template for this node group. | ||
| func (asg *Asg) TemplateNodeInfo() (*framework.NodeInfo, error) { | ||
| func (asg *Asg) TemplateNodeInfo(ctx context.Context) (*framework.NodeInfo, error) { | ||
| template, err := asg.manager.getAsgTemplate(asg.id) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -202,28 +203,28 @@ func (asg *Asg) TemplateNodeInfo() (*framework.NodeInfo, error) { | |
|
|
||
| // Exist checks if the node group really exists on the cloud provider side. Allows to tell the | ||
| // theoretical node group from the real one. | ||
| func (asg *Asg) Exist() bool { | ||
| func (asg *Asg) Exist(ctx context.Context) bool { | ||
| return true | ||
| } | ||
|
|
||
| // Create creates the node group on the cloud provider side. | ||
| func (asg *Asg) Create() (cloudprovider.NodeGroup, error) { | ||
| func (asg *Asg) Create(ctx context.Context) (cloudprovider.NodeGroup, error) { | ||
| return nil, cloudprovider.ErrNotImplemented | ||
| } | ||
|
|
||
| // Autoprovisioned returns true if the node group is autoprovisioned. | ||
| func (asg *Asg) Autoprovisioned() bool { | ||
| func (asg *Asg) Autoprovisioned(ctx context.Context) bool { | ||
| return false | ||
| } | ||
|
|
||
| // Delete deletes the node group on the cloud provider side. | ||
| // This will be executed only for autoprovisioned node groups, once their size drops to 0. | ||
| func (asg *Asg) Delete() error { | ||
| func (asg *Asg) Delete(ctx context.Context) error { | ||
| return cloudprovider.ErrNotImplemented | ||
| } | ||
|
|
||
| // GetOptions returns NodeGroupAutoscalingOptions that should be used for this particular | ||
| // NodeGroup. Returning a nil will result in using default options. | ||
| func (asg *Asg) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*config.NodeGroupAutoscalingOptions, error) { | ||
| func (asg *Asg) GetOptions(ctx context.Context, defaults config.NodeGroupAutoscalingOptions) (*config.NodeGroupAutoscalingOptions, error) { | ||
| return nil, cloudprovider.ErrNotImplemented | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ limitations under the License. | |
| package alicloud | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
@@ -113,22 +114,22 @@ func (ali *aliCloudProvider) Name() string { | |
| } | ||
|
|
||
| // GPULabel returns the label added to nodes with GPU resource. | ||
| func (ali *aliCloudProvider) GPULabel() string { | ||
| func (ali *aliCloudProvider) GPULabel(ctx context.Context) string { | ||
| return GPULabel | ||
| } | ||
|
|
||
| // GetAvailableGPUTypes return all available GPU types cloud provider supports | ||
| func (ali *aliCloudProvider) GetAvailableGPUTypes() map[string]struct{} { | ||
| func (ali *aliCloudProvider) GetAvailableGPUTypes(ctx context.Context) map[string]struct{} { | ||
| return availableGPUTypes | ||
| } | ||
|
|
||
| // GetNodeGpuConfig returns the label, type and resource name for the GPU added to node. If node doesn't have | ||
| // any GPUs, it returns nil. | ||
| func (ali *aliCloudProvider) GetNodeGpuConfig(node *apiv1.Node) *cloudprovider.GpuConfig { | ||
| return gpu.GetNodeGPUFromCloudProvider(ali, node) | ||
| func (ali *aliCloudProvider) GetNodeGpuConfig(ctx context.Context, node *apiv1.Node) *cloudprovider.GpuConfig { | ||
| return gpu.GetNodeGPUFromCloudProvider(context.TODO(), ali, node) | ||
| } | ||
|
Comment on lines
+128
to
130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Propagate the received context to downstream work. These methods accept
Proposed pattern- return gpu.GetNodeGPUFromCloudProvider(context.TODO(), provider, node)
+ return gpu.GetNodeGPUFromCloudProvider(ctx, provider, node)
- nodes, err := group.Nodes(context.TODO())
+ nodes, err := group.Nodes(ctx)
- pools, err := client.ListPools(context.Background(), clusterID)
+ pools, err := client.ListPools(ctx, clusterID)📍 Affects 8 files
🤖 Prompt for AI Agents |
||
|
|
||
| func (ali *aliCloudProvider) NodeGroups() []cloudprovider.NodeGroup { | ||
| func (ali *aliCloudProvider) NodeGroups(ctx context.Context) []cloudprovider.NodeGroup { | ||
| result := make([]cloudprovider.NodeGroup, 0, len(ali.asgs)) | ||
| for _, asg := range ali.asgs { | ||
| result = append(result, asg) | ||
|
|
@@ -137,7 +138,7 @@ func (ali *aliCloudProvider) NodeGroups() []cloudprovider.NodeGroup { | |
| } | ||
|
|
||
| // NodeGroupForNode returns the node group for the given node. | ||
| func (ali *aliCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.NodeGroup, error) { | ||
| func (ali *aliCloudProvider) NodeGroupForNode(ctx context.Context, node *apiv1.Node) (cloudprovider.NodeGroup, error) { | ||
| if len(node.Spec.ProviderID) == 0 { | ||
| klog.Warningf("Node %v has no providerId", node.Name) | ||
| return nil, nil | ||
|
|
@@ -158,39 +159,39 @@ func (ali *aliCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.N | |
| } | ||
|
|
||
| // HasInstance returns whether a given node has a corresponding instance in this cloud provider | ||
| func (ali *aliCloudProvider) HasInstance(*apiv1.Node) (bool, error) { | ||
| func (ali *aliCloudProvider) HasInstance(context.Context, *apiv1.Node) (bool, error) { | ||
| return true, cloudprovider.ErrNotImplemented | ||
| } | ||
|
|
||
| // Pricing returns pricing model for this cloud provider or error if not available. | ||
| func (ali *aliCloudProvider) Pricing() (cloudprovider.PricingModel, errors.AutoscalerError) { | ||
| func (ali *aliCloudProvider) Pricing(ctx context.Context) (cloudprovider.PricingModel, errors.AutoscalerError) { | ||
| return nil, cloudprovider.ErrNotImplemented | ||
| } | ||
|
|
||
| // GetAvailableMachineTypes get all machine types that can be requested from the cloud provider. | ||
| func (ali *aliCloudProvider) GetAvailableMachineTypes() ([]string, error) { | ||
| func (ali *aliCloudProvider) GetAvailableMachineTypes(ctx context.Context) ([]string, error) { | ||
| return []string{}, nil | ||
| } | ||
|
|
||
| // NewNodeGroup builds a theoretical node group based on the node definition provided. The node group is not automatically | ||
| // created on the cloud provider side. The node group is not returned by NodeGroups() until it is created. | ||
| func (ali *aliCloudProvider) NewNodeGroup(machineType string, labels map[string]string, systemLabels map[string]string, taints []apiv1.Taint, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) { | ||
| func (ali *aliCloudProvider) NewNodeGroup(ctx context.Context, machineType string, labels map[string]string, systemLabels map[string]string, taints []apiv1.Taint, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) { | ||
| return nil, cloudprovider.ErrNotImplemented | ||
| } | ||
|
|
||
| // GetResourceLimiter returns struct containing limits (max, min) for resources (cores, memory etc.). | ||
| func (ali *aliCloudProvider) GetResourceLimiter() (*cloudprovider.ResourceLimiter, error) { | ||
| func (ali *aliCloudProvider) GetResourceLimiter(ctx context.Context) (*cloudprovider.ResourceLimiter, error) { | ||
| return ali.resourceLimiter, nil | ||
| } | ||
|
|
||
| // Refresh is called before every main loop and can be used to dynamically update cloud provider state. | ||
| // In particular the list of node groups returned by NodeGroups can change as a result of CloudProvider.Refresh(). | ||
| func (ali *aliCloudProvider) Refresh() error { | ||
| func (ali *aliCloudProvider) Refresh(ctx context.Context) error { | ||
| return nil | ||
| } | ||
|
|
||
| // Cleanup stops the go routine that is handling the current view of the ASGs in the form of a cache | ||
| func (ali *aliCloudProvider) Cleanup() error { | ||
| func (ali *aliCloudProvider) Cleanup(ctx context.Context) error { | ||
| return nil | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double-checking - before a given provider adapts, the global
klogcalls will continue working as before, right?