-
Notifications
You must be signed in to change notification settings - Fork 71
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
feat: Add ACI Spot virtual nodes support to virtual kubelet #192
Open
telotlik
wants to merge
28
commits into
virtual-kubelet:master
Choose a base branch
from
telotlik:telotlik/VKACISpotContainers
base: master
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.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
63da061
Add priority as annotation to use spot containers for virtual kubelet
telotlik 151530d
Add new test to validate null priority
telotlik d8fda88
Updating priority check in pod annotation
telotlik 74fd22c
Update tests and add priority annotation const
telotlik 3f23906
Update priority string check
telotlik d803498
Iterate on ACI Spot CG on Virtual Kubelets - new function for propert…
suselva b3bc432
Merge pull request #1 from telotlik/users/suselva/aci-spot
suselva cc15b33
api version when using priority
fnuarnav c0e15d8
update: set apiVersion based on extensible list of Tags
fnuarnav fb1a943
use VersioProvider to check ContainerGroupProperties
fnuarnav bbc2355
fix indentation; validate version format
fnuarnav c4c3b0a
Revert "fix indentation; validate version format"
fnuarnav bc57388
version set in code follows correct format
fnuarnav 49c3e26
added unit tests for versioning
fnuarnav 2843053
update logging; use more c# style documentation comments
fnuarnav f2a006a
remove print stmt; log uri in create
fnuarnav 7f42078
fix indents
fnuarnav 2b1c322
use virtual-kubelet.io/priority; update comment
fnuarnav a35c90a
use tag name virtual-kubelet.io-proprity
fnuarnav b75b772
fix typo
fnuarnav bd6bc81
set priority Tag with correct values only when priority annotaiton is…
fnuarnav e222422
clean up code
fnuarnav d780b79
define priorityTagNae as a constant
fnuarnav 35334f6
Merge pull request #3 from telotlik/users/arnav/review-comments
fnuarnav 7c147e3
Merge remote-tracking branch 'upstream/master' into telotlik/VKACISpo…
fnuarnav 79ce469
Merge branch 'telotlik/VKACISpotContainers' into users/arnav/api-version
fnuarnav 9613c46
fixed typo in comment
fnuarnav 122d8bc
try adding parallelism to avoid timeout
fnuarnav 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
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,70 @@ | ||
package aci | ||
|
||
import ( | ||
"github.com/virtual-kubelet/virtual-kubelet/log" | ||
"context" | ||
) | ||
|
||
//<summary> | ||
// map of minimum api version required for different properties | ||
// TODO: read from a separate json file if it gets too large | ||
//</summary> | ||
var minVersionSupport = map[string]string { | ||
"Priority": "2021-10-01", | ||
} | ||
|
||
//<summary> | ||
// VersionProvider struct for selecting api version based on various properties | ||
// Maintains the api version selected after checking certain property | ||
//<summary> | ||
type VersionProvider struct { | ||
finalVersion string | ||
} | ||
|
||
//<summary> | ||
// creates a new instance of VErsionProvider, and sets default version | ||
// assumes api version to be of the format YYYY-mm-dd[-suffix] | ||
// assumes that the api version format will not be violated | ||
//</summary> | ||
//<param name="defaultVersion"> The default api version </param> | ||
//<returns> | ||
// reference to an instance of the verison provider object | ||
//</returns> | ||
func newVersionProvider(defaultVersion string) (*VersionProvider) { | ||
return &VersionProvider{defaultVersion} | ||
} | ||
|
||
//<summary> | ||
// get the api version for the specific ContainerGroup instance based on various properties | ||
//</summary> | ||
//<param name="containerGroup"> the ContainerGroup instance for which version is to be selected </param> | ||
//<param name="ctx"> the Context to be used for logging </param> | ||
//<returns> | ||
// reference to an instance of VersionProvider with the finalVersion field updated | ||
//</returns> | ||
func (versionProvider *VersionProvider) getVersion(containerGroup ContainerGroup, ctx context.Context) (* VersionProvider) { | ||
|
||
versionProvider.setVersionFromProperty(string(containerGroup.ContainerGroupProperties.Priority), "Priority", ctx) | ||
|
||
log.G(ctx).Infof("API Version set to %s \n", versionProvider.finalVersion) | ||
return versionProvider | ||
} | ||
|
||
//<summary> | ||
// find the min api version for a string property based on the value in minVersionSupport map | ||
// assumes that the api version always uses the correct format YYYY-mm-dd[-suffix] | ||
//</summary> | ||
//<param name="property">the string value of some property field that should be checked<param> | ||
//<param name="keyRef">the key for the property in the minVersionSupport map</param> | ||
//<param name="ctx">the context to be used for logging</param> | ||
//<returns> | ||
// reference to an instance of VersionProvider with the finalVersion field updated | ||
//</returns> | ||
func (versionProvider *VersionProvider) setVersionFromProperty(property string, keyRef string, ctx context.Context) (*VersionProvider) { | ||
minVersion, ok := minVersionSupport[keyRef] | ||
if len(property) > 0 && ok && versionProvider.finalVersion < minVersion { | ||
versionProvider.finalVersion = minVersion | ||
} | ||
log.G(ctx).Infof("Selected API Version %s for property %s with value %s \n", versionProvider.finalVersion, keyRef, property) | ||
return versionProvider | ||
} |
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,85 @@ | ||
package aci | ||
|
||
import ( | ||
"testing" | ||
"context" | ||
"gotest.tools/assert" | ||
is "gotest.tools/assert/cmp" | ||
) | ||
|
||
// tests setlecting version when property is present in map | ||
func TestSetVersionFromPropertyInMap(t *testing.T) { | ||
key := "Priority" | ||
defaultVersion := apiVersion | ||
versionProvider:= newVersionProvider(defaultVersion) | ||
|
||
// should use defualt version when property is not populated | ||
versionProvider.setVersionFromProperty("", key, context.Background()) | ||
assert.Check(t, is.Equal(versionProvider.finalVersion, defaultVersion), "Default version should be used when a property value is empty") | ||
|
||
// should use api version present in map if priority is Spot | ||
versionProvider.setVersionFromProperty("Spot", key, context.Background()) | ||
assert.Check(t, is.Equal(versionProvider.finalVersion, minVersionSupport[key]), "When a version is available for the property in map, the final version should be >= min api version for the property") | ||
|
||
// should use api version present in map if priority is Regular | ||
versionProvider.setVersionFromProperty("Regular", key, context.Background()) | ||
assert.Check(t, is.Equal(versionProvider.finalVersion, minVersionSupport[key]), "When a version is available for the property in map, the final version should be >= min api version for the property") | ||
|
||
} | ||
|
||
// tests selecting version when a property is present in map with version < defualtVersion | ||
func TestSetLowerVersionFromPropertyInMap (t *testing.T) { | ||
key := "Priority" | ||
largeDefaultVersion := "9999-99-99" | ||
versionProvider := newVersionProvider(largeDefaultVersion) | ||
|
||
// should use largeDefaultVersion as it is > the min api version for this key | ||
versionProvider.setVersionFromProperty("Regular", key, context.Background()) | ||
assert.Check(t, versionProvider.finalVersion >= minVersionSupport[key], "Use larger version among default and min api versions for various properties") | ||
} | ||
|
||
// test selecting version when property is not present in map | ||
func TestSetVersionFromPropertyNotInMap(t *testing.T) { | ||
key := "someUnknownKey" | ||
defaultVersion := apiVersion | ||
versionProvider:= newVersionProvider(defaultVersion) | ||
|
||
// should use default version when property is not present in map | ||
versionProvider.setVersionFromProperty("propertyValue", key, context.Background()) | ||
assert.Check(t, versionProvider.finalVersion == defaultVersion, "Default version should be used when no version for a property is available in map") | ||
} | ||
|
||
// test getVersion for ContainerGroup with Priority | ||
func TestGetVersionForContainerGroupWithPriority(t *testing.T) { | ||
key := "Priority" | ||
versionProvider := newVersionProvider(apiVersion) | ||
containerGroup := ContainerGroup{ | ||
Location: "eastus", | ||
ContainerGroupProperties: ContainerGroupProperties{ | ||
Priority: Spot, | ||
OsType: Linux, | ||
}, | ||
} | ||
|
||
// should use api version in map when priority is set for a containerGroup | ||
versionProvider.getVersion(containerGroup, context.Background()) | ||
assert.Check(t, is.Equal(versionProvider.finalVersion, minVersionSupport[key]), "Use api version in map when priority is set for a containerGroup") | ||
|
||
} | ||
|
||
// test getVersion for containerGroup without Priority | ||
func TestGetVersionForContainerGroupWithoutPriority(t *testing.T) { | ||
defaultVersion := apiVersion | ||
versionProvider := newVersionProvider(defaultVersion) | ||
containerGroup := ContainerGroup{ | ||
Location: "eastus", | ||
ContainerGroupProperties: ContainerGroupProperties{ | ||
OsType: Linux, | ||
}, | ||
} | ||
|
||
// should use default api version when priority is not set for a containerGroup | ||
versionProvider.getVersion(containerGroup, context.Background()) | ||
assert.Check(t, is.Equal(versionProvider.finalVersion, defaultVersion), "Use default api version when priority is not set for a containerGroup") | ||
|
||
} |
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
Oops, something went wrong.
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.
Since the priority is not an explicit parameter to this function, this comment should explain how priority is passed in, if we already mention what the accepted values are :)
Additionally, as far as I can tell from the code, it is also allowed not to specify it at all, so I'd recommend mentioning that too.