Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f89afa00
Commit
f89afa00
authored
Feb 14, 2018
by
Kenneth Owens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update versioned portions of kubectl to use apps/v1 with DaemonSet
parent
cf80186a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
57 deletions
+15
-57
history.go
pkg/kubectl/history.go
+10
-14
rollback.go
pkg/kubectl/rollback.go
+5
-43
No files found.
pkg/kubectl/history.go
View file @
f89afa00
...
...
@@ -23,9 +23,8 @@ import (
"text/tabwriter"
appsv1
"k8s.io/api/apps/v1"
appsv1beta1
"k8s.io/api/apps/v1beta1"
"k8s.io/api/core/v1"
extensionsv1beta1
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/api/meta"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
...
...
@@ -35,8 +34,6 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/kubernetes"
clientappsv1
"k8s.io/client-go/kubernetes/typed/apps/v1"
clientappsv1beta1
"k8s.io/client-go/kubernetes/typed/apps/v1beta1"
clientextv1beta1
"k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
api
"k8s.io/kubernetes/pkg/apis/core"
apiv1
"k8s.io/kubernetes/pkg/apis/core/v1"
deploymentutil
"k8s.io/kubernetes/pkg/controller/deployment/util"
...
...
@@ -187,11 +184,11 @@ type DaemonSetHistoryViewer struct {
// ViewHistory returns a revision-to-history map as the revision history of a deployment
// TODO: this should be a describer
func
(
h
*
DaemonSetHistoryViewer
)
ViewHistory
(
namespace
,
name
string
,
revision
int64
)
(
string
,
error
)
{
ds
,
history
,
err
:=
daemonSetHistory
(
h
.
c
.
ExtensionsV1beta1
(),
h
.
c
.
AppsV1beta
1
(),
namespace
,
name
)
ds
,
history
,
err
:=
daemonSetHistory
(
h
.
c
.
AppsV
1
(),
namespace
,
name
)
if
err
!=
nil
{
return
""
,
err
}
historyInfo
:=
make
(
map
[
int64
]
*
appsv1
beta1
.
ControllerRevision
)
historyInfo
:=
make
(
map
[
int64
]
*
appsv1
.
ControllerRevision
)
for
_
,
history
:=
range
history
{
// TODO: for now we assume revisions don't overlap, we may need to handle it
historyInfo
[
history
.
Revision
]
=
history
...
...
@@ -290,11 +287,11 @@ func controlledHistoryV1(
// controlledHistories returns all ControllerRevisions in namespace that selected by selector and owned by accessor
func
controlledHistory
(
apps
clientappsv1
beta1
.
AppsV1beta
1Interface
,
apps
clientappsv1
.
AppsV
1Interface
,
namespace
string
,
selector
labels
.
Selector
,
accessor
metav1
.
Object
)
([]
*
appsv1
beta1
.
ControllerRevision
,
error
)
{
var
result
[]
*
appsv1
beta1
.
ControllerRevision
accessor
metav1
.
Object
)
([]
*
appsv1
.
ControllerRevision
,
error
)
{
var
result
[]
*
appsv1
.
ControllerRevision
historyList
,
err
:=
apps
.
ControllerRevisions
(
namespace
)
.
List
(
metav1
.
ListOptions
{
LabelSelector
:
selector
.
String
()})
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -311,10 +308,9 @@ func controlledHistory(
// daemonSetHistory returns the DaemonSet named name in namespace and all ControllerRevisions in its history.
func
daemonSetHistory
(
ext
clientextv1beta1
.
ExtensionsV1beta1Interface
,
apps
clientappsv1beta1
.
AppsV1beta1Interface
,
namespace
,
name
string
)
(
*
extensionsv1beta1
.
DaemonSet
,
[]
*
appsv1beta1
.
ControllerRevision
,
error
)
{
ds
,
err
:=
ext
.
DaemonSets
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{})
apps
clientappsv1
.
AppsV1Interface
,
namespace
,
name
string
)
(
*
appsv1
.
DaemonSet
,
[]
*
appsv1
.
ControllerRevision
,
error
)
{
ds
,
err
:=
apps
.
DaemonSets
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to retrieve DaemonSet %s: %v"
,
name
,
err
)
}
...
...
@@ -357,7 +353,7 @@ func statefulSetHistory(
}
// applyDaemonSetHistory returns a specific revision of DaemonSet by applying the given history to a copy of the given DaemonSet
func
applyDaemonSetHistory
(
ds
*
extensionsv1beta1
.
DaemonSet
,
history
*
appsv1beta1
.
ControllerRevision
)
(
*
extensionsv1beta
1
.
DaemonSet
,
error
)
{
func
applyDaemonSetHistory
(
ds
*
appsv1
.
DaemonSet
,
history
*
appsv1
.
ControllerRevision
)
(
*
appsv
1
.
DaemonSet
,
error
)
{
clone
:=
ds
.
DeepCopy
()
cloneBytes
,
err
:=
json
.
Marshal
(
clone
)
if
err
!=
nil
{
...
...
pkg/kubectl/rollback.go
View file @
f89afa00
...
...
@@ -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
.
AppsV1beta
1
(),
accessor
.
GetNamespace
(),
accessor
.
GetName
())
ds
,
history
,
err
:=
daemonSetHistory
(
r
.
c
.
AppsV
1
(),
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
:=
findHistory
V1
(
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.
// 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
{
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
[]
*
appsv1
beta1
.
ControllerRevision
)
*
appsv1beta
1
.
ControllerRevision
{
func
findHistory
(
toRevision
int64
,
allHistory
[]
*
appsv1
.
ControllerRevision
)
*
appsv
1
.
ControllerRevision
{
if
toRevision
==
0
&&
len
(
allHistory
)
<=
1
{
return
nil
}
// Find the history to rollback to
var
toHistory
*
appsv1
beta1
.
ControllerRevision
var
toHistory
*
appsv1
.
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
[]
*
appsv1
beta1
.
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment