Skip to content

Commit 0936e22

Browse files
authored
Merge pull request #79 from jtherin/release-0.21-pick-74
feat: added label for nulling instancesV2 interface
2 parents f5d4bc3 + c457c18 commit 0936e22

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

scaleway/servers.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import (
1515
const (
1616
InstanceTypeInstance = "instance"
1717
InstanceTypeBaremtal = "baremetal"
18+
19+
// nodeLabelDisableLifeCycle is a label for nulling cloudprovider.InstancesV2 interface
20+
nodeLabelDisableLifeCycle = "k8s.scw.cloud/disable-lifcycle"
21+
22+
// nodeLabelNodePublicIP is a label to override External-IP of a node
23+
nodeLabelNodePublicIP = "k8s.scw.cloud/node-public-ip"
1824
)
1925

2026
type Servers interface {
@@ -167,6 +173,10 @@ func (s *servers) GetZoneByNodeName(ctx context.Context, nodeName types.NodeName
167173
// InstanceExists returns true if the instance for the given node exists according to the cloud provider.
168174
// Use the node.name or node.spec.providerID field to find the node in the cloud provider.
169175
func (s *servers) InstanceExists(ctx context.Context, node *v1.Node) (bool, error) {
176+
if _, ok := node.Labels[nodeLabelDisableLifeCycle]; ok {
177+
return true, nil
178+
}
179+
170180
if node.Spec.ProviderID == "" {
171181
exists, err := s.instances.InstanceExists(ctx, node)
172182
if err != nil {
@@ -183,6 +193,10 @@ func (s *servers) InstanceExists(ctx context.Context, node *v1.Node) (bool, erro
183193
// InstanceShutdown returns true if the instance is shutdown according to the cloud provider.
184194
// Use the node.name or node.spec.providerID field to find the node in the cloud provider.
185195
func (s *servers) InstanceShutdown(ctx context.Context, node *v1.Node) (bool, error) {
196+
if _, ok := node.Labels[nodeLabelDisableLifeCycle]; ok {
197+
return false, nil
198+
}
199+
186200
if node.Spec.ProviderID == "" {
187201
shutdown, err := s.instances.InstanceShutdown(ctx, node)
188202
if err == cloudprovider.InstanceNotFound {
@@ -197,6 +211,15 @@ func (s *servers) InstanceShutdown(ctx context.Context, node *v1.Node) (bool, er
197211
// translated into specific fields in the Node object on registration.
198212
// Use the node.name or node.spec.providerID field to find the node in the cloud provider.
199213
func (s *servers) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprovider.InstanceMetadata, error) {
214+
if address, ok := node.Labels[nodeLabelNodePublicIP]; ok {
215+
return &cloudprovider.InstanceMetadata{
216+
NodeAddresses: []v1.NodeAddress{{
217+
Type: v1.NodeExternalIP,
218+
Address: address,
219+
}},
220+
}, nil
221+
}
222+
200223
if node.Spec.ProviderID == "" {
201224
metadata, err := s.instances.InstanceMetadata(ctx, node)
202225
if err == cloudprovider.InstanceNotFound {

0 commit comments

Comments
 (0)