Skip to content

Commit

Permalink
pkg/scaffold/cmd.go: Skip erroring out on Service
Browse files Browse the repository at this point in the history
If the Service could not be created we just log the error instead of
erroring out and exiting. This error could occur when there is more than
one pods such as with leader election. In that case the new pod will
expose the metrics via the already created Service object.
  • Loading branch information
lilic committed Dec 10, 2018
1 parent 97bc078 commit 93be61a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/scaffold/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"github.com/operator-framework/operator-sdk/pkg/metrics"
"github.com/operator-framework/operator-sdk/pkg/ready"
sdkVersion "github.com/operator-framework/operator-sdk/version"
apierrors "k8s.io/apimachinery/pkg/api/errors"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -131,7 +132,7 @@ func main() {
os.Exit(1)
}
client := mgr.GetClient()
if err := client.Create(context.TODO(), s); err != nil {
if err := client.Create(context.TODO(), s); err != nil && !apierrors.IsAlreadyExists(err) {
log.Error(err, "")
os.Exit(1)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/scaffold/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/operator-framework/operator-sdk/pkg/metrics"
"github.com/operator-framework/operator-sdk/pkg/ready"
sdkVersion "github.com/operator-framework/operator-sdk/version"
apierrors "k8s.io/apimachinery/pkg/api/errors"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -129,7 +130,7 @@ func main() {
os.Exit(1)
}
client := mgr.GetClient()
if err := client.Create(context.TODO(), s); err != nil {
if err := client.Create(context.TODO(), s); err != nil && !apierrors.IsAlreadyExists(err) {
log.Error(err, "")
os.Exit(1)
}
Expand Down

0 comments on commit 93be61a

Please sign in to comment.