From 2fe8fd2473871bb8daf3a2333d2a84fb5676125a Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Wed, 1 Aug 2018 19:44:09 -0700 Subject: [PATCH 1/2] main: use hostname and uuid to identify leader It's possible that two instances of the CVO could run in a single pod. The UUID will protect against this case. --- cmd/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 7ac317f6a0..845c741afc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -10,6 +10,7 @@ import ( "github.com/openshift/cluster-version-operator/pkg/version" "github.com/golang/glog" + "github.com/google/uuid" "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -100,9 +101,14 @@ func createResourceLock(config *rest.Config) resourcelock.Interface { glog.Fatalf("Failed to create leader-election client: %v", err) } - id := os.Getenv("POD_NAME") - if id == "" { - glog.Fatalf("Failed to find POD_NAME in environment") + id, err := os.Hostname() + if err != nil { + glog.Fatalf("Failed to determine hostname: %v", err) + } + + uuid, err := uuid.NewRandom() + if err != nil { + glog.Fatalf("Failed to generate UUID: %v", err) } return &resourcelock.ConfigMapLock{ @@ -112,7 +118,7 @@ func createResourceLock(config *rest.Config) resourcelock.Interface { }, Client: leaderElectionClient.CoreV1(), LockConfig: resourcelock.ResourceLockConfig{ - Identity: id, + Identity: id + "_" + uuid.String(), EventRecorder: recorder, }, } From fd8b72e3bc536bc787f2dd992b4734d79ef30d34 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Wed, 1 Aug 2018 19:45:21 -0700 Subject: [PATCH 2/2] apis/cvo: properly parse urls The previous implementation didn't account for the opening and closing quotes that surround a string. This also updates the default upstream Cincinnati URL to include the graph API endpoint. --- pkg/apis/clusterversion.openshift.io/v1/url.go | 11 ++++++++--- pkg/cvo/update.go | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/apis/clusterversion.openshift.io/v1/url.go b/pkg/apis/clusterversion.openshift.io/v1/url.go index 5c98596458..82bc804e25 100644 --- a/pkg/apis/clusterversion.openshift.io/v1/url.go +++ b/pkg/apis/clusterversion.openshift.io/v1/url.go @@ -1,17 +1,22 @@ package v1 import ( + "encoding/json" "net/url" ) // UnmarshalJSON unmarshals a URL, ensuring that it is valid. func (u *URL) UnmarshalJSON(data []byte) error { - _, err := url.Parse(string(data)) - if err != nil { + var raw string + if err := json.Unmarshal(data, &raw); err != nil { return err } - *u = URL(string(data)) + if _, err := url.Parse(raw); err != nil { + return err + } + + *u = URL(raw) return nil } diff --git a/pkg/cvo/update.go b/pkg/cvo/update.go index 3ddfe4b4d1..9243278c94 100644 --- a/pkg/cvo/update.go +++ b/pkg/cvo/update.go @@ -16,7 +16,7 @@ import ( ) var ( - defaultUpstream = v1.URL("http://localhost:8080") + defaultUpstream = v1.URL("http://localhost:8080/graph") defaultChannel = "fast" )