Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
67fc1a21
Commit
67fc1a21
authored
Feb 10, 2017
by
Adam Reese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(kube): support upgrading ThirdPartyResources
parent
f55a4355
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
+14
-14
client.go
pkg/kube/client.go
+13
-13
client_test.go
pkg/kube/client_test.go
+1
-1
No files found.
pkg/kube/client.go
View file @
67fc1a21
...
...
@@ -29,6 +29,7 @@ import (
jsonpatch
"github.com/evanphx/json-patch"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/v1"
apps
"k8s.io/kubernetes/pkg/apis/apps/v1beta1"
"k8s.io/kubernetes/pkg/apis/batch"
...
...
@@ -353,18 +354,12 @@ func deleteResource(c *Client, info *resource.Info) error {
return
reaper
.
Stop
(
info
.
Namespace
,
info
.
Name
,
0
,
nil
)
}
func
createPatch
(
target
*
resource
.
Info
,
currentObj
runtime
.
Object
)
([]
byte
,
api
.
PatchType
,
error
)
{
// Get a versioned object
versionedObject
,
err
:=
api
.
Scheme
.
New
(
target
.
Mapping
.
GroupVersionKind
)
if
err
!=
nil
{
return
nil
,
api
.
StrategicMergePatchType
,
fmt
.
Errorf
(
"failed to get versionedObject: %s"
,
err
)
}
oldData
,
err
:=
json
.
Marshal
(
currentObj
)
func
createPatch
(
mapping
*
meta
.
RESTMapping
,
target
,
current
runtime
.
Object
)
([]
byte
,
api
.
PatchType
,
error
)
{
oldData
,
err
:=
json
.
Marshal
(
current
)
if
err
!=
nil
{
return
nil
,
api
.
StrategicMergePatchType
,
fmt
.
Errorf
(
"serializing current configuration: %s"
,
err
)
}
newData
,
err
:=
json
.
Marshal
(
target
.
Object
)
newData
,
err
:=
json
.
Marshal
(
target
)
if
err
!=
nil
{
return
nil
,
api
.
StrategicMergePatchType
,
fmt
.
Errorf
(
"serializing target configuration: %s"
,
err
)
}
...
...
@@ -373,19 +368,24 @@ func createPatch(target *resource.Info, currentObj runtime.Object) ([]byte, api.
return
nil
,
api
.
StrategicMergePatchType
,
nil
}
switch
target
.
Object
.
(
type
)
{
case
*
runtime
.
Unstructured
:
// Get a versioned object
versionedObject
,
err
:=
api
.
Scheme
.
New
(
mapping
.
GroupVersionKind
)
switch
{
case
runtime
.
IsNotRegisteredError
(
err
)
:
// fall back to generic JSON merge patch
patch
,
err
:=
jsonpatch
.
CreateMergePatch
(
oldData
,
newData
)
return
patch
,
api
.
MergePatchType
,
err
case
err
!=
nil
:
return
nil
,
api
.
StrategicMergePatchType
,
fmt
.
Errorf
(
"failed to get versionedObject: %s"
,
err
)
default
:
log
.
Printf
(
"generating strategic merge patch for %T"
,
target
.
Object
)
log
.
Printf
(
"generating strategic merge patch for %T"
,
target
)
patch
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
versionedObject
)
return
patch
,
api
.
StrategicMergePatchType
,
err
}
}
func
updateResource
(
c
*
Client
,
target
*
resource
.
Info
,
currentObj
runtime
.
Object
,
recreate
bool
)
error
{
patch
,
patchType
,
err
:=
createPatch
(
target
,
currentObj
)
patch
,
patchType
,
err
:=
createPatch
(
target
.
Mapping
,
target
.
Object
,
currentObj
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create patch: %s"
,
err
)
}
...
...
pkg/kube/client_test.go
View file @
67fc1a21
...
...
@@ -169,7 +169,7 @@ func TestUpdate(t *testing.T) {
t
.
Fatalf
(
"could not dump request: %s"
,
err
)
}
req
.
Body
.
Close
()
expected
:=
`{"spec":{"containers":[{"
image":"abc/app:v4","name":"app:v4","ports":[{"containerPort":443,"name":"https"}],"resources":{}
}]}}`
expected
:=
`{"spec":{"containers":[{"
name":"app:v4","ports":[{"containerPort":443,"name":"https"},{"$patch":"delete","containerPort":80}]
}]}}`
if
string
(
data
)
!=
expected
{
t
.
Errorf
(
"expected patch
\n
%s
\n
got
\n
%s"
,
expected
,
string
(
data
))
}
...
...
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