Skip to content
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: ListNodeImageVersions + shared image gallery support #526

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1cb133c
feat: support shared image galleries inside of karpenter
Bryce-Soghigian Oct 15, 2024
db34e35
chore: populating image stubs for shared image galleries
Bryce-Soghigian Oct 15, 2024
ac5e943
fix: progress
Bryce-Soghigian Oct 15, 2024
78fc1ec
fix: PopulateResourceStub accessing the wrong index
Bryce-Soghigian Oct 15, 2024
24ec40f
test: properly testing ListNodeImageVersions
Bryce-Soghigian Oct 16, 2024
c79ecfd
refactor: rename symbol for SIG Subscription id
Bryce-Soghigian Oct 16, 2024
f19c719
test: conditional use of sig dependent on the managed karpenter flag
Bryce-Soghigian Oct 16, 2024
107b41f
refactor: removing panics used in testing
Bryce-Soghigian Oct 16, 2024
9c179cc
test: adding RBAC and helm values to the template for SIG Gallery logic
Bryce-Soghigian Oct 16, 2024
3f7f761
fix: bug in azure linux sig image resolution
Bryce-Soghigian Oct 16, 2024
0efac0d
chore: update cleanupenv to handle inflate too ratehr than just job pods
Bryce-Soghigian Oct 16, 2024
637e30e
test: fix randomized test order flake
Bryce-Soghigian Oct 16, 2024
0d7a98a
ci: shadow declaration
Bryce-Soghigian Oct 16, 2024
13b410d
refactor: comment wording
Bryce-Soghigian Oct 16, 2024
05e4ac9
test: validate all image ids are resolved correctly
Bryce-Soghigian Oct 16, 2024
283484d
fix: adding filtering for duplicate sku + os combinations and filteri…
Bryce-Soghigian Oct 16, 2024
227f7d6
refactor: renaming var
Bryce-Soghigian Oct 30, 2024
340f481
refactor: rename the managedKarpenter reference to UseSIG
Bryce-Soghigian Nov 14, 2024
1901a83
refactor: spelling
Bryce-Soghigian Nov 14, 2024
cc07eb7
fix: v1 migration for test
Bryce-Soghigian Nov 15, 2024
4b05f7f
ci: lint
Bryce-Soghigian Nov 15, 2024
29deb55
fix: lint
Bryce-Soghigian Nov 15, 2024
059f5ce
ci: fix
Bryce-Soghigian Nov 26, 2024
1690673
Merge branch 'main' into bsoghigian/list-node-image-versions-poc
Bryce-Soghigian Nov 26, 2024
a31607f
ci: license
Bryce-Soghigian Nov 29, 2024
ae9aee7
ci: fix
Bryce-Soghigian Nov 29, 2024
b3a3c7c
fix: test pollution
Bryce-Soghigian Dec 2, 2024
e320b04
fix: resetting options before each test run
Bryce-Soghigian Dec 3, 2024
50b828e
fix: accounting for versions of the shape 'yy.mm.dd'
Bryce-Soghigian Dec 3, 2024
a8918e6
Merge branch 'main' into bsoghigian/list-node-image-versions-poc
Bryce-Soghigian Dec 3, 2024
03f42ae
test: removing unused cleanup funcs
Bryce-Soghigian Dec 7, 2024
3593316
fix: making the key for shared image gallery smaller
Bryce-Soghigian Dec 7, 2024
21816ff
refactor: removing windows types leaving them to be added back later
Bryce-Soghigian Dec 7, 2024
3df028a
refactor: reducing key even more
Bryce-Soghigian Dec 7, 2024
f1e83de
fix: extending key
Bryce-Soghigian Dec 7, 2024
3ee67d5
Merge branch 'main' into bsoghigian/list-node-image-versions-poc
Bryce-Soghigian Dec 7, 2024
856538d
fix: removing log line
Bryce-Soghigian Dec 7, 2024
bb47fe1
refactor: not nesting options as deep, leaving refactor of USESIG to …
Bryce-Soghigian Dec 7, 2024
1027429
fix: comment about pulling out the variable
Bryce-Soghigian Dec 7, 2024
8c5fd4a
refactor: decoupling the cache reads and cache writes from the image …
Bryce-Soghigian Dec 9, 2024
c0add8d
test: adding some coverage to FilteredNodeImages
Bryce-Soghigian Dec 9, 2024
c5dfa26
refactor: removing community galleries fake method for GET since this…
Bryce-Soghigian Dec 9, 2024
64a6fa6
test: test that we drift nodes when switching from community gallery …
Bryce-Soghigian Dec 9, 2024
5cc3757
test: SIG_SUBSCRIPTION_ID
Bryce-Soghigian Dec 16, 2024
2337c05
Merge branch 'bsoghigian/list-node-image-versions-poc' of github.com:…
Bryce-Soghigian Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions pkg/providers/imagefamily/nodeimageversionsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
Expand Down Expand Up @@ -102,21 +104,29 @@ func FilteredNodeImages(nodeImageVersions []NodeImageVersion) []NodeImageVersion
return filteredImages
}

// isNewerVersion will return if version1 is greater than version2, note the new versioning scheme is yearmm.dd.build, previously it was yy.mm.dd without the build id.
tallaxes marked this conversation as resolved.
Show resolved Hide resolved
func isNewerVersion(version1, version2 string) bool {
Bryce-Soghigian marked this conversation as resolved.
Show resolved Hide resolved
// Assuming version is in the format: "year.month.day.build"
// Split by dots and compare each segment as an integer
// Split by dots and compare each segment as an integer getting the largest vhd version
v1Segments := strings.Split(version1, ".")
v2Segments := strings.Split(version2, ".")

var v1, v2 [4]int
fmt.Sscanf(version1, "%d.%d.%d.%d", &v1[0], &v1[1], &v1[2], &v1[3]) //nolint:errcheck
fmt.Sscanf(version2, "%d.%d.%d.%d", &v2[0], &v2[1], &v2[2], &v2[3]) //nolint:errcheck
for i := 0; i < len(v1Segments) && i < len(v2Segments); i++ {
v1Segment, err1 := strconv.Atoi(v1Segments[i])
v2Segment, err2 := strconv.Atoi(v2Segments[i])

for i := 0; i < 4; i++ {
if v1[i] > v2[i] {
if err1 != nil || err2 != nil {
return false
}

if v1Segment > v2Segment {
return true
} else if v1[i] < v2[i] {
} else if v1Segment < v2Segment {
return false
}
}

return false
// If all segments are equal up to the length of the shorter version,
// the longer version is considered newer if it has additional segments
// the legacy linux versions use "yy.mm.dd" whereas new linux versions use "yymm.dd.build"
return len(v1Segments) > len(v2Segments)
}
49 changes: 49 additions & 0 deletions pkg/providers/imagefamily/nodeimageversionsclient_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Portions Copyright (c) Microsoft Corporation.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package imagefamily

import (
"testing"
)

func TestIsNewerVersion(t *testing.T) {
testCases := []struct {
version1 string
version2 string
expected bool
}{
{"202308.28.0", "202411.12.0", false},
{"202411.12.0", "202308.28.0", true},
{"202202.08.29", "202405.20.0", false},
{"202404.09.0", "202411.12.0", false},
{"202405.20.0", "202404.09.0", true},
{"2022.10.03", "2022.12.15", false},
{"202411.12.0", "2022.12.15", true},
{"2022.12.15", "2022.10.03", true},
{"202411.12.0", "202411.12.0", false},
{"2o2411.12.0", "202411.12.0", false}, // invalid version strings should be ignored and return false
}

for _, tc := range testCases {
t.Run(tc.version1+"_"+tc.version2, func(t *testing.T) {
result := isNewerVersion(tc.version1, tc.version2)
if result != tc.expected {
t.Errorf("isNewerVersion(%q, %q) = %v; want %v", tc.version1, tc.version2, result, tc.expected)
}
})
}
}
Loading