Skip to content

Commit 7f0695f

Browse files
authored
chore: defaulting latest release version and v-prefix compatible (#137)
Signed-off-by: yue9944882 <[email protected]>
1 parent 10e7165 commit 7f0695f

File tree

5 files changed

+50
-50
lines changed

5 files changed

+50
-50
lines changed

pkg/cmd/init/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
5151
cmd.Flags().StringVar(&o.registry, "image-registry", "quay.io/open-cluster-management",
5252
"The name of the image registry serving OCM images, which will be applied to all the deploying OCM components.")
5353
cmd.Flags().StringVar(&o.bundleVersion, "bundle-version", "default",
54-
"the version of predefined compatible image versions")
54+
`the version of predefined compatible image versions. e.g. v0.6.0, defaulted to the latest release version. also, we can set "latest" to install latest develop version`)
5555
cmd.Flags().StringVar(&o.outputJoinCommandFile, "output-join-command-file", "",
5656
"If set, the generated join command be saved to the prescribed file.")
5757
cmd.Flags().BoolVar(&o.wait, "wait", false,

pkg/cmd/init/options.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Options struct {
1919
force bool
2020
//Pulling image registry of OCM
2121
registry string
22-
//version of predefined compatible image versions
22+
//version of predefined compatible image versions
2323
bundleVersion string
2424
//If set, will be persisting the generated join command to a local file
2525
outputJoinCommandFile string
@@ -28,22 +28,21 @@ type Options struct {
2828
}
2929

3030
type BundleVersion struct {
31-
// registation image version
31+
// registation image version
3232
RegistrationImageVersion string
33-
// placment image version
33+
// placment image version
3434
PlacementImageVersion string
35-
// work image version
35+
// work image version
3636
WorkImageVersion string
37-
// operator image version
38-
OperatorImageVersion string
37+
// operator image version
38+
OperatorImageVersion string
3939
}
4040

41-
4241
//Valus: The values used in the template
4342
type Values struct {
4443
//The values related to the hub
4544
Hub Hub `json:"hub"`
46-
//bundle version
45+
//bundle version
4746
BundleVersion BundleVersion
4847
}
4948

@@ -57,8 +56,6 @@ type Hub struct {
5756
Registry string `json:"registry"`
5857
}
5958

60-
61-
6259
func newOptions(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericclioptions.IOStreams) *Options {
6360
return &Options{
6461
ClusteradmFlags: clusteradmFlags,

pkg/cmd/join/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
4949
cmd.Flags().StringVar(&o.outputFile, "output-file", "", "The generated resources will be copied in the specified file")
5050
cmd.Flags().StringVar(&o.registry, "image-registry", "quay.io/open-cluster-management", "The name of the image registry serving OCM images.")
5151
cmd.Flags().StringVar(&o.bundleVersion, "bundle-version", "default",
52-
"version of predefined compatible image versions")
52+
"version of predefined compatible image versions")
5353
cmd.Flags().BoolVar(&o.forceHubInClusterEndpointLookup, "force-internal-endpoint-lookup", false,
5454
"If true, the installed klusterlet agent will be starting the cluster registration process by "+
5555
"looking for the internal endpoint from the public cluster-info in the hub cluster instead of from --hub-apiserver.")

pkg/cmd/join/options.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type Options struct {
2020
values Values
2121
//The file to output the resources will be sent to the file.
2222
outputFile string
23-
//version of predefined compatible image versions
24-
bundleVersion string
23+
//version of predefined compatible image versions
24+
bundleVersion string
2525
//Pulling image registry of OCM
2626
registry string
2727
//Runs the cluster joining in foreground
@@ -43,7 +43,7 @@ type Values struct {
4343
Registry string
4444
//ImageRegistry is the klusterlet related configuration
4545
Klusterlet Klusterlet
46-
//bundle version
46+
//bundle version
4747
BundleVersion BundleVersion
4848
}
4949

@@ -65,18 +65,16 @@ type Klusterlet struct {
6565
}
6666

6767
type BundleVersion struct {
68-
// registation image version
68+
// registation image version
6969
RegistrationImageVersion string
70-
// placment image version
70+
// placment image version
7171
PlacementImageVersion string
72-
// work image version
72+
// work image version
7373
WorkImageVersion string
74-
// operator image version
75-
OperatorImageVersion string
74+
// operator image version
75+
OperatorImageVersion string
7676
}
7777

78-
79-
8078
func newOptions(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericclioptions.IOStreams) *Options {
8179
return &Options{
8280
ClusteradmFlags: clusteradmFlags,

pkg/helpers/version/version.go

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,55 @@
22
package version
33

44
import (
5-
"errors"
5+
"fmt"
6+
"strings"
67
)
78

8-
type VersionBundle struct {
9+
type VersionBundle struct {
910
Registration string
10-
Placement string
11-
Work string
12-
Operator string
13-
}
11+
Placement string
12+
Work string
13+
Operator string
14+
}
1415

16+
func GetVersionBundle(version string) (VersionBundle, error) {
1517

16-
func GetVersionBundle(version string ) (VersionBundle ,error){
18+
// supporting either "x.y.z" or "vx.y.z" format version
19+
if strings.HasPrefix(version, "v") {
20+
version = strings.TrimPrefix(version, "v")
21+
}
1722

1823
versionBundleList := map[string]VersionBundle{}
1924

20-
// default
21-
versionBundleList["default"] = VersionBundle{
25+
// latest
26+
versionBundleList["latest"] = VersionBundle{
2227
Registration: "latest",
23-
Placement: "latest",
24-
Work: "latest",
25-
Operator: "latest",
28+
Placement: "latest",
29+
Work: "latest",
30+
Operator: "latest",
2631
}
27-
28-
// predifined bundle version
29-
versionBundleList["0.5.0"] = VersionBundle{
30-
Registration: "0.5.0",
31-
Placement: "0.2.0",
32-
Work: "0.5.0",
33-
Operator: "0.5.0",
3432

33+
// predifined bundle version
34+
// TODO: automated version tracking
35+
versionBundleList["0.5.0"] = VersionBundle{
36+
Registration: "v0.5.0",
37+
Placement: "v0.2.0",
38+
Work: "v0.5.0",
39+
Operator: "v0.5.0",
3540
}
3641

3742
versionBundleList["0.6.0"] = VersionBundle{
38-
Registration: "0.6.0",
39-
Placement: "0.3.0",
40-
Work: "0.6.0",
41-
Operator: "0.6.0",
43+
Registration: "v0.6.0",
44+
Placement: "v0.3.0",
45+
Work: "v0.6.0",
46+
Operator: "v0.6.0",
4247
}
4348

49+
// default
50+
versionBundleList["default"] = versionBundleList["0.6.0"]
4451

4552
if val, ok := versionBundleList[version]; ok {
46-
return val , nil
47-
}
48-
no_version_error := errors.New("couldn't find the requested version bundle")
49-
return VersionBundle{}, no_version_error
53+
return val, nil
54+
}
55+
return VersionBundle{}, fmt.Errorf("couldn't find the requested version bundle: %v", version)
5056
}
51-

0 commit comments

Comments
 (0)