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

Ingress upgrade testing fixes #567

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmd/e2e-test/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ func TestUpgrade(t *testing.T) {
AddPath("test.com", "/", "service-1", intstr.FromInt(80)).
Build()

if _, err := Framework.Clientset.Extensions().Ingresses(s.Namespace).Create(newIng); err != nil {
if _, err := Framework.Clientset.Extensions().Ingresses(s.Namespace).Update(newIng); err != nil {
t.Fatalf("error creating Ingress spec: %v", err)
} else {
// If Ingress upgrade succeeds, we update the status on this Ingress
// to Unstable. It is set back to Stable after WaitForIngress below
// finishes successfully.
s.PutStatus(e2e.Unstable)
needUpdate = false
}
Expand All @@ -91,10 +94,10 @@ func TestUpgrade(t *testing.T) {
if err != nil {
t.Fatalf("error waiting for Ingress to stabilize: %v", err)
}
s.PutStatus(e2e.Stable)

if runs == 0 {
t.Logf("GCLB resources created (%s/%s)", s.Namespace, tc.ing.Name)
s.PutStatus(e2e.Stable)
} else {
t.Logf("GCLB is stable (%s/%s)", s.Namespace, tc.ing.Name)
}
Expand Down
27 changes: 23 additions & 4 deletions pkg/e2e/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,21 @@ func (sm *StatusManager) init() error {
newIndexer := func() cache.Indexers {
return cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}
}
stopCh := make(chan struct{})
cmInformer := informerv1.NewConfigMapInformer(sm.f.Clientset, "default", cmPollInterval, newIndexer())
cmInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(old, cur interface{}) {
curCm := cur.(*v1.ConfigMap)
if len(curCm.Data[exitKey]) > 0 {
glog.V(2).Infof("ConfigMap was updated with exit switch at %s", curCm.Data[exitKey])
close(stopCh)
sm.f.shutdown(0)
}
},
})

go cmInformer.Run(stopCh)

go func() {
for _ = range time.NewTicker(flushInterval).C {
sm.flush()
Expand Down Expand Up @@ -132,7 +136,7 @@ func (sm *StatusManager) putStatus(key string, status IngressStability) {

func (sm *StatusManager) masterUpgraded() bool {
if len(sm.cm.Data[masterUpgraded]) > 0 {
glog.V(2).Infof("Master has successfully upgraded at %s", sm.cm.Data[masterUpgraded])
glog.V(4).Infof("Master has successfully upgraded at %s", sm.cm.Data[masterUpgraded])
return true
}
return false
Expand All @@ -144,8 +148,23 @@ func (sm *StatusManager) flush() {

// Loop until we successfully update the config map
for {
var err error
sm.cm, err = sm.f.Clientset.Core().ConfigMaps("default").Update(sm.cm)
updatedCm, err := sm.f.Clientset.Core().ConfigMaps("default").Get(configMapName, metav1.GetOptions{})
if err != nil {
glog.Errorf("Error getting ConfigMap: %v", err)
}

if updatedCm.Data == nil {
updatedCm.Data = make(map[string]string)
}

// K8s considers its version of the ConfigMap to be latest, so we must get
// the configmap from k8s first, then merge in our data.
for key, value := range sm.cm.Data {
updatedCm.Data[key] = value
}
sm.cm = updatedCm

_, err = sm.f.Clientset.Core().ConfigMaps("default").Update(sm.cm)
if err != nil {
glog.Errorf("Error updating ConfigMap: %v", err)
} else {
Expand All @@ -154,5 +173,5 @@ func (sm *StatusManager) flush() {
}
}
glog.V(3).Infof("Flushed statuses to ConfigMap")
glog.V(3).Infof("ConfigMap: %+v", sm.cm.Data)
glog.V(3).Infof("ConfigMap: %+v", sm.cm)
}