-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topology-updater: Add Node OwnerReference to NRTs
Add the corresponding Node as OwnerReference in thr NRT, so it gets deleted if the Node object gets deleted, to avoid leftovers in the cluster.
- Loading branch information
1 parent
c26ee82
commit 99d956f
Showing
8 changed files
with
272 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package nrtupdater | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
var NotConfigured = errors.New("unconfigured feature") | ||
|
||
type NotFound struct { | ||
NodeName string | ||
} | ||
|
||
func (err NotFound) Error() string { | ||
return "node " + err.NodeName + " Not Found" | ||
} | ||
|
||
type ConnectionError struct { | ||
Err error | ||
} | ||
|
||
func (err ConnectionError) Error() string { | ||
return fmt.Sprintf("error connection k8s: %v", err.Err) | ||
} | ||
func (err ConnectionError) Unwrap() error { | ||
return err.Err | ||
} | ||
|
||
type NodeGetter interface { | ||
Get(ctx context.Context, nodeName string, opts metav1.GetOptions) (*corev1.Node, error) | ||
} | ||
|
||
type DisabledNodeGetter struct { | ||
} | ||
|
||
func (ng *DisabledNodeGetter) Get(ctx context.Context, nodeName string, opts metav1.GetOptions) (*corev1.Node, error) { | ||
return nil, fmt.Errorf("%w", NotConfigured) | ||
} | ||
|
||
type CachedNodeGetter struct { | ||
nodes map[string]*corev1.Node | ||
} | ||
|
||
func NewCachedNodeGetter(k8sInterface kubernetes.Interface, ctx context.Context) *CachedNodeGetter { | ||
nodelist, err := k8sInterface.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
retVal := &CachedNodeGetter{nodes: make(map[string]*corev1.Node, len(nodelist.Items))} | ||
for idx := range nodelist.Items { | ||
node := &nodelist.Items[idx] | ||
retVal.nodes[node.Name] = node | ||
} | ||
|
||
return retVal | ||
} | ||
|
||
func (ng *CachedNodeGetter) Get(ctx context.Context, nodeName string, _ metav1.GetOptions) (*corev1.Node, error) { | ||
if node, found := ng.nodes[nodeName]; found { | ||
return node, nil | ||
} | ||
return nil, fmt.Errorf("%w", NotFound{NodeName: nodeName}) | ||
} | ||
|
||
func NewNodeGetter(enabled bool, k8xcli kubernetes.Interface, ctx context.Context) NodeGetter { | ||
if enabled { | ||
ret := NewCachedNodeGetter(k8xcli, ctx) | ||
if ret == nil { | ||
return nil | ||
} | ||
return ret | ||
} | ||
return &DisabledNodeGetter{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"NRTupdater":{"NoPublish":false,"Oneshot":false,"Hostname":"TEST_NODE"},"Resourcemonitor":{"Namespace":"","SysfsRoot":"/sys","ResourceExclude":null,"RefreshNodeResources":false,"PodSetFingerprint":true,"PodSetFingerprintMethod":"with-exclusive-resources","ExposeTiming":false,"PodSetFingerprintStatusFile":"","PodExclude":null,"ExcludeTerminalPods":false},"RTE":{"Debug":false,"ReferenceContainer":{"Namespace":"TEST_NS","PodName":"TEST_POD","ContainerName":"TEST_CONT"},"TopologyManagerPolicy":"","TopologyManagerScope":"","KubeletConfigFile":"/podresources/config.yaml","PodResourcesSocketPath":"unix:///podresources/kubelet.sock","SleepInterval":60000000000,"PodReadinessEnable":true,"NotifyFilePath":"","MaxEventsPerTimeUnit":1,"TimeUnitToLimitEvents":1000000000},"Version":false,"DumpConfig":""} | ||
{"NRTupdater":{"NoPublish":false,"Oneshot":false,"Hostname":"TEST_NODE"},"Resourcemonitor":{"Namespace":"","SysfsRoot":"/sys","ResourceExclude":null,"RefreshNodeResources":false,"PodSetFingerprint":true,"PodSetFingerprintMethod":"with-exclusive-resources","ExposeTiming":false,"PodSetFingerprintStatusFile":"","PodExclude":null,"ExcludeTerminalPods":false},"RTE":{"Debug":false,"ReferenceContainer":{"Namespace":"TEST_NS","PodName":"TEST_POD","ContainerName":"TEST_CONT"},"TopologyManagerPolicy":"","TopologyManagerScope":"","KubeletConfigFile":"/podresources/config.yaml","PodResourcesSocketPath":"unix:///podresources/kubelet.sock","SleepInterval":60000000000,"PodReadinessEnable":true,"NotifyFilePath":"","MaxEventsPerTimeUnit":1,"TimeUnitToLimitEvents":1000000000,"AddNRTOwnerEnable":true},"Version":false,"DumpConfig":""} |
Oops, something went wrong.