Skip to content

Commit 853b25c

Browse files
authored
Merge pull request #109 from hasbro17/haseeb/add-sdk-version
*: add versioning to sdk and version constraint for generated project
2 parents 510e91e + 80a51c3 commit 853b25c

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

pkg/generator/gen_main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222

2323
const (
2424
// sdkImport is the operator-sdk import path.
25-
sdkImport = "github.com/coreos/operator-sdk/pkg/sdk"
25+
sdkImport = "github.com/coreos/operator-sdk/pkg/sdk"
26+
versionImport = "github.com/coreos/operator-sdk/version"
2627
)
2728

2829
// Main contains all the customized data needed to generate cmd/<projectName>/main.go for a new operator
@@ -31,6 +32,7 @@ type Main struct {
3132
// imports
3233
OperatorSDKImport string
3334
StubImport string
35+
SDKVersionImport string
3436
}
3537

3638
// renderMainFile generates the cmd/<projectName>/main.go file given a repo path ("github.com/coreos/play")
@@ -44,6 +46,7 @@ func renderMainFile(w io.Writer, repo string) error {
4446
m := Main{
4547
OperatorSDKImport: sdkImport,
4648
StubImport: filepath.Join(repo, stubDir),
49+
SDKVersionImport: versionImport,
4750
}
4851
return t.Execute(w, m)
4952
}

pkg/generator/generator_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ const mainExp = `package main
2323
2424
import (
2525
"context"
26+
"runtime"
2627
2728
stub "github.com/coreos/play/pkg/stub"
2829
sdk "github.com/coreos/operator-sdk/pkg/sdk"
30+
sdkVersion "github.com/coreos/operator-sdk/version"
31+
32+
"github.com/sirupsen/logrus"
2933
)
3034
35+
func printVersion() {
36+
logrus.Infof("Go Version: %s", runtime.Version())
37+
logrus.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
38+
logrus.Infof("operator-sdk Version: %v", sdkVersion.Version)
39+
}
40+
3141
func main() {
42+
printVersion()
3243
sdk.Watch("apps/v1", "Deployment", "default")
3344
sdk.Handle(stub.NewHandler())
3445
sdk.Run(context.TODO())

pkg/generator/gopkg_tmpls.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,10 @@ const gopkgTomlTmpl = `[[override]]
160160
[[override]]
161161
name = "k8s.io/client-go"
162162
version = "kubernetes-1.9.3"
163+
164+
[[constraint]]
165+
name = "github.com/coreos/operator-sdk"
166+
# The version rule is used for a specific release and the master branch for in between releases.
167+
branch = "master"
168+
# version = "v0.0.1"
163169
`

pkg/generator/main_tmpl.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ const mainTmpl = `package main
1919
2020
import (
2121
"context"
22+
"runtime"
2223
2324
stub "{{.StubImport}}"
2425
sdk "{{.OperatorSDKImport}}"
26+
sdkVersion "{{.SDKVersionImport}}"
27+
28+
"github.com/sirupsen/logrus"
2529
)
2630
31+
func printVersion() {
32+
logrus.Infof("Go Version: %s", runtime.Version())
33+
logrus.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
34+
logrus.Infof("operator-sdk Version: %v", sdkVersion.Version)
35+
}
36+
2737
func main() {
38+
printVersion()
2839
sdk.Watch("apps/v1", "Deployment", "default")
2940
sdk.Handle(stub.NewHandler())
3041
sdk.Run(context.TODO())

version/version.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2018 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package version
16+
17+
var (
18+
Version = "v0.0.0+git"
19+
)

0 commit comments

Comments
 (0)