Update versioned portions of kubectl to use apps/v1 with DaemonSet
This commit is contained in:
@@ -25,7 +25,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
"k8s.io/api/core/v1"
|
||||
extv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
@@ -257,7 +256,7 @@ func (r *DaemonSetRollbacker) Rollback(obj runtime.Object, updatedAnnotations ma
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create accessor for kind %v: %s", obj.GetObjectKind(), err.Error())
|
||||
}
|
||||
ds, history, err := daemonSetHistory(r.c.ExtensionsV1beta1(), r.c.AppsV1beta1(), accessor.GetNamespace(), accessor.GetName())
|
||||
ds, history, err := daemonSetHistory(r.c.AppsV1(), accessor.GetNamespace(), accessor.GetName())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -316,7 +315,7 @@ func (r *StatefulSetRollbacker) Rollback(obj runtime.Object, updatedAnnotations
|
||||
return "", fmt.Errorf("no last revision to roll back to")
|
||||
}
|
||||
|
||||
toHistory := findHistoryV1(toRevision, history)
|
||||
toHistory := findHistory(toRevision, history)
|
||||
if toHistory == nil {
|
||||
return "", revisionNotFoundErr(toRevision)
|
||||
}
|
||||
@@ -346,44 +345,16 @@ func (r *StatefulSetRollbacker) Rollback(obj runtime.Object, updatedAnnotations
|
||||
return rollbackSuccess, nil
|
||||
}
|
||||
|
||||
// TODO: When all the controllers have been updated to use v1, rename this function findHistoryV1()->findHistory() and
|
||||
// TODO: remove the original findHistory()
|
||||
// findHistoryV1 returns a controllerrevision of a specific revision from the given controllerrevisions.
|
||||
// findHistory returns a controllerrevision of a specific revision from the given controllerrevisions.
|
||||
// It returns nil if no such controllerrevision exists.
|
||||
// If toRevision is 0, the last previously used history is returned.
|
||||
func findHistoryV1(toRevision int64, allHistory []*appsv1.ControllerRevision) *appsv1.ControllerRevision {
|
||||
func findHistory(toRevision int64, allHistory []*appsv1.ControllerRevision) *appsv1.ControllerRevision {
|
||||
if toRevision == 0 && len(allHistory) <= 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Find the history to rollback to
|
||||
var toHistory *appsv1.ControllerRevision
|
||||
if toRevision == 0 {
|
||||
// If toRevision == 0, find the latest revision (2nd max)
|
||||
sort.Sort(historiesByRevisionV1(allHistory))
|
||||
toHistory = allHistory[len(allHistory)-2]
|
||||
} else {
|
||||
for _, h := range allHistory {
|
||||
if h.Revision == toRevision {
|
||||
// If toRevision != 0, find the history with matching revision
|
||||
return h
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toHistory
|
||||
}
|
||||
|
||||
// findHistory returns a controllerrevision of a specific revision from the given controllerrevisions.
|
||||
// It returns nil if no such controllerrevision exists.
|
||||
// If toRevision is 0, the last previously used history is returned.
|
||||
func findHistory(toRevision int64, allHistory []*appsv1beta1.ControllerRevision) *appsv1beta1.ControllerRevision {
|
||||
if toRevision == 0 && len(allHistory) <= 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Find the history to rollback to
|
||||
var toHistory *appsv1beta1.ControllerRevision
|
||||
if toRevision == 0 {
|
||||
// If toRevision == 0, find the latest revision (2nd max)
|
||||
sort.Sort(historiesByRevision(allHistory))
|
||||
@@ -417,19 +388,10 @@ func revisionNotFoundErr(r int64) error {
|
||||
}
|
||||
|
||||
// TODO: copied from daemon controller, should extract to a library
|
||||
type historiesByRevision []*appsv1beta1.ControllerRevision
|
||||
type historiesByRevision []*appsv1.ControllerRevision
|
||||
|
||||
func (h historiesByRevision) Len() int { return len(h) }
|
||||
func (h historiesByRevision) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
||||
func (h historiesByRevision) Less(i, j int) bool {
|
||||
return h[i].Revision < h[j].Revision
|
||||
}
|
||||
|
||||
// TODO: copied from daemon controller, should extract to a library
|
||||
type historiesByRevisionV1 []*appsv1.ControllerRevision
|
||||
|
||||
func (h historiesByRevisionV1) Len() int { return len(h) }
|
||||
func (h historiesByRevisionV1) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
||||
func (h historiesByRevisionV1) Less(i, j int) bool {
|
||||
return h[i].Revision < h[j].Revision
|
||||
}
|
||||
|
Reference in New Issue
Block a user