-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1397 from mrostecki/4.2-fix-image-list
[4.2] addons: List cilium-init image only for Cilium < 1.6
- Loading branch information
Showing
7 changed files
with
176 additions
and
5 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
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,34 @@ | ||
/* | ||
* Copyright (c) 2020 SUSE LLC. | ||
* | ||
* 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 util | ||
|
||
import ( | ||
"github.com/blang/semver" | ||
) | ||
|
||
func VersionCompare(versionS, constraintS string) bool { | ||
version, err := semver.ParseTolerant(versionS) | ||
if err != nil { | ||
panic(err) | ||
} | ||
constraint, err := semver.ParseRange(constraintS) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return constraint(version) | ||
} |
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,113 @@ | ||
/* | ||
* Copyright (c) 2020 SUSE LLC. | ||
* | ||
* 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 util | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestVersionCompare(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
version string | ||
constraint string | ||
exp bool | ||
}{ | ||
{ | ||
name: "equal, should match", | ||
version: "1.7.5", | ||
constraint: "1.7.5", | ||
exp: true, | ||
}, | ||
{ | ||
name: "greater or equal, should match", | ||
version: "1.7.5", | ||
constraint: ">=1.7.5", | ||
exp: true, | ||
}, | ||
{ | ||
name: "lower or equal, should match", | ||
version: "1.7.5", | ||
constraint: "<=1.7.5", | ||
exp: true, | ||
}, | ||
{ | ||
name: "greater, should match", | ||
version: "1.7.5", | ||
constraint: ">1.7.0", | ||
exp: true, | ||
}, | ||
{ | ||
name: "lower, should match", | ||
version: "1.7.5", | ||
constraint: "<1.8.0", | ||
exp: true, | ||
}, | ||
{ | ||
name: "equal, should not match, is lower", | ||
version: "1.7.5", | ||
constraint: "1.5.3", | ||
exp: false, | ||
}, | ||
{ | ||
name: "equal, should not match, is greater", | ||
version: "1.7.5", | ||
constraint: "1.8.0", | ||
exp: false, | ||
}, | ||
{ | ||
name: "greater, should not match", | ||
version: "1.7.5", | ||
constraint: ">1.7.5", | ||
exp: false, | ||
}, | ||
{ | ||
name: "lower, should not match", | ||
version: "1.7.5", | ||
constraint: "<1.7.5", | ||
exp: false, | ||
}, | ||
{ | ||
name: "greater or equal, should not match", | ||
version: "1.7.5", | ||
constraint: ">=1.8.0", | ||
exp: false, | ||
}, | ||
{ | ||
name: "lower or equal, should not match", | ||
version: "1.7.5", | ||
constraint: "<=1.5.0", | ||
exp: false, | ||
}, | ||
{ | ||
name: "greater, with rev", | ||
version: "1.6.6-rev5", | ||
constraint: ">1.6.0", | ||
exp: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
cmp := VersionCompare(tt.version, tt.constraint) | ||
if cmp != tt.exp { | ||
t.Errorf("version comparison does not match, expected %v, got %v", tt.exp, cmp) | ||
} | ||
}) | ||
} | ||
} |