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

Error: cannot use resyncPeriod (type int) as type time.Duration in argument to sdk.Watch #453

Closed
jianzhangbjz opened this issue Sep 2, 2018 · 4 comments

Comments

@jianzhangbjz
Copy link
Contributor

I created a Operator named jian-operator via the Operator-SDK, seems it works well. But, I got below errors when I building its image:

[root@localhost jian-operator]# operator-sdk build quay.io/example/jian-operator
Error: failed to build: (building jian-operator...
# github.com/example-inc/jian-operator/cmd/jian-operator
cmd/jian-operator/main.go:35:11: cannot use resyncPeriod (type int) as type time.Duration in argument to sdk.Watch
)

Below is the main.go file, seems like need to add a conversion between the type int and the type time.

[root@localhost jian-operator]# cat cmd/jian-operator/main.go 
package main

import (
	"context"
	"runtime"

	stub "github.com/example-inc/jian-operator/pkg/stub"
	sdk "github.com/operator-framework/operator-sdk/pkg/sdk"
	k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
	sdkVersion "github.com/operator-framework/operator-sdk/version"

	"github.com/sirupsen/logrus"
	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

func printVersion() {
	logrus.Infof("Go Version: %s", runtime.Version())
	logrus.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
	logrus.Infof("operator-sdk Version: %v", sdkVersion.Version)
}

func main() {
	printVersion()

	sdk.ExposeMetricsPort()

	resource := "jian.example.com/v1alpha1"
	kind := "App"
	namespace, err := k8sutil.GetWatchNamespace()
	if err != nil {
		logrus.Fatalf("Failed to get watch namespace: %v", err)
	}
	resyncPeriod := 5
	logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod)
	sdk.Watch(resource, kind, namespace, resyncPeriod)
	sdk.Handle(stub.NewHandler())
	sdk.Run(context.TODO())
}

It's strange that it works before, you can see other operators I created before, but why failed now?

[root@localhost example-inc]# ls
app-operator  jian-operator  memcached-operator

I also checked the the template for cmd/main.go , seems this issue has been fixed. We can see the time package now. So, do I need to update my operator-sdk tool? If yes, how to update it?

[root@localhost example-inc]# operator-sdk --version
operator-sdk version 0.0.5+git
@fanminshi
Copy link
Contributor

@jianzhangbjz we decided to use time.duration instead of int for sdk.Watch via #427.
That's why it breaks on you.

do I need to update my operator-sdk tool?
To be safe, you should update regardless. I don't know how old your tool is because operator-sdk version 0.0.5+git doesn't tell me which hash it is built upon. To update your tool, you should simply run make install in your operator-sdk dir e.g .../github.com/operator-framework/operator-sdk.

@hasbro17
Copy link
Contributor

hasbro17 commented Sep 4, 2018

@jianzhangbjz That was breaking change made recently.
It's been a long time since we've cut a new tag for the SDK so v0.0.5 is quite outdated.
For now can you please checkout and build the SDK from the master branch:

git checkout master
make install

And for an existing operator project you can update the Gopkg.toml file to update the dependency to the master branch:

[[constraint]]
  name = "github.com/operator-framework/operator-sdk"
  # The version rule is used for a specific release and the master branch for in between releases.
  branch = "master"
  # version = "=v0.0.5"

And then run dep ensure to update.

We're planning to do a release at the end of this week to not force users to use the master branch. At that point you can use the latest tag.

@jianzhangbjz
Copy link
Contributor Author

jianzhangbjz commented Sep 5, 2018

@fanminshi @hasbro17 Thanks a lot! It works now!

I don't know how old your tool is because operator-sdk version 0.0.5+git doesn't tell me which hash it is built upon.

[root@localhost operator-sdk]# operator-sdk --version
operator-sdk version 0.0.5+git

I think we should fix the version issue, what do you think?

@AlexNPavel
Copy link
Contributor

@jianzhangbjz v0.0.6 has been released. You can set your projects' Gopkg.toml files to use that version instead of the master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants