-
Notifications
You must be signed in to change notification settings - Fork 47
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
Added topology aware volume scheduling for node service #33
Open
AmitRoushan
wants to merge
1
commit into
Huawei:developing
Choose a base branch
from
AmitRoushan:topology-node-plugin-modification
base: developing
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
package driver | ||
|
||
import ( | ||
"strings" | ||
"utils/k8sutils" | ||
) | ||
|
||
type Driver struct { | ||
name string | ||
version string | ||
useMultiPath bool | ||
isNeedMultiPath bool | ||
k8sUtils k8sutils.Interface | ||
nodeName string | ||
} | ||
|
||
func NewDriver(name, version string, useMultiPath, isNeedMultiPath bool) *Driver { | ||
func NewDriver(name, version string, useMultiPath, isNeedMultiPath bool, | ||
k8sUtils k8sutils.Interface, nodeName string) *Driver { | ||
return &Driver{ | ||
name: name, | ||
version: version, | ||
useMultiPath: useMultiPath, | ||
isNeedMultiPath: isNeedMultiPath, | ||
k8sUtils: k8sUtils, | ||
nodeName: strings.TrimSpace(nodeName), | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package k8sutils | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"regexp" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
const ( | ||
topologyRegx = "topology.kubernetes.io/*" | ||
) | ||
|
||
type Interface interface { | ||
GetNodeTopology(nodeName string) (map[string]string, error) | ||
} | ||
|
||
type KubeClient struct { | ||
clientSet *kubernetes.Clientset | ||
} | ||
|
||
func NewK8SUtils(kubeConfig string) (Interface, error) { | ||
var clientset *kubernetes.Clientset | ||
|
||
if kubeConfig != "" { | ||
config, err := clientcmd.BuildConfigFromFlags("", kubeConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clientset, err = kubernetes.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
config, err := rest.InClusterConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clientset, err = kubernetes.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &KubeClient{ | ||
clientSet: clientset, | ||
}, nil | ||
} | ||
|
||
func (k *KubeClient) GetNodeTopology(nodeName string) (map[string]string, error) { | ||
k8sNode, err := k.getNode(nodeName) | ||
if err != nil { | ||
return nil, errors.New(fmt.Sprintf("failed to get node topology with error: %v", err)) | ||
} | ||
|
||
topology := make(map[string]string) | ||
for key, value := range k8sNode.Labels { | ||
if match, err := regexp.MatchString(topologyRegx, key); err == nil && match { | ||
topology[key] = value | ||
} | ||
} | ||
|
||
return topology, nil | ||
} | ||
|
||
func (k *KubeClient) getNode(nodeName string) (*corev1.Node, error) { | ||
return k.clientSet.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{}) | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same here
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.
Updated environment variable name as per suggestion