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
27243875
Unverified
Commit
27243875
authored
Feb 05, 2018
by
Matthew Fisher
Committed by
GitHub
Feb 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3373 from unguiculus/feature/fix-recreate-part-1
Fix pod recreation
parents
add98dab
ea520afd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
35 deletions
+59
-35
client.go
pkg/kube/client.go
+59
-35
No files found.
pkg/kube/client.go
View file @
27243875
...
...
@@ -27,10 +27,12 @@ import (
"time"
jsonpatch
"github.com/evanphx/json-patch"
apps
"k8s.io/api/apps/v1beta2"
appsv1
"k8s.io/api/apps/v1"
appsv1beta1
"k8s.io/api/apps/v1beta1"
appsv1beta2
"k8s.io/api/apps/v1beta2"
batch
"k8s.io/api/batch/v1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
extv1beta1
"k8s.io/api/extensions/v1beta1"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
...
...
@@ -428,40 +430,39 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
if
err
:=
target
.
Get
();
err
!=
nil
{
return
fmt
.
Errorf
(
"error trying to refresh resource information: %v"
,
err
)
}
return
nil
}
// send patch to server
helper
:=
resource
.
NewHelper
(
target
.
Client
,
target
.
Mapping
)
obj
,
err
:=
helper
.
Patch
(
target
.
Namespace
,
target
.
Name
,
patchType
,
patch
)
if
err
!=
nil
{
kind
:=
target
.
Mapping
.
GroupVersionKind
.
Kind
log
.
Printf
(
"Cannot patch %s: %q (%v)"
,
kind
,
target
.
Name
,
err
)
}
else
{
// send patch to server
helper
:=
resource
.
NewHelper
(
target
.
Client
,
target
.
Mapping
)
if
force
{
// Attempt to delete...
if
err
:=
deleteResource
(
c
,
target
);
err
!=
nil
{
obj
,
err
:=
helper
.
Patch
(
target
.
Namespace
,
target
.
Name
,
patchType
,
patch
)
if
err
!=
nil
{
kind
:=
target
.
Mapping
.
GroupVersionKind
.
Kind
log
.
Printf
(
"Cannot patch %s: %q (%v)"
,
kind
,
target
.
Name
,
err
)
if
force
{
// Attempt to delete...
if
err
:=
deleteResource
(
c
,
target
);
err
!=
nil
{
return
err
}
log
.
Printf
(
"Deleted %s: %q"
,
kind
,
target
.
Name
)
// ... and recreate
if
err
:=
createResource
(
target
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to recreate resource: %s"
,
err
)
}
log
.
Printf
(
"Created a new %s called %q
\n
"
,
kind
,
target
.
Name
)
// No need to refresh the target, as we recreated the resource based
// on it. In addition, it might not exist yet and a call to `Refresh`
// may fail.
}
else
{
log
.
Print
(
"Use --force to force recreation of the resource"
)
return
err
}
log
.
Printf
(
"Deleted %s: %q"
,
kind
,
target
.
Name
)
// ... and recreate
if
err
:=
createResource
(
target
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to recreate resource: %s"
,
err
)
}
log
.
Printf
(
"Created a new %s called %q
\n
"
,
kind
,
target
.
Name
)
// No need to refresh the target, as we recreated the resource based
// on it. In addition, it might not exist yet and a call to `Refresh`
// may fail.
}
else
{
log
.
Print
(
"Use --force to force recreation of the resource"
)
return
err
// When patch succeeds without needing to recreate, refresh target.
target
.
Refresh
(
obj
,
true
)
}
}
else
{
// When patch succeeds without needing to recreate, refresh target.
target
.
Refresh
(
obj
,
true
)
}
if
!
recreate
{
...
...
@@ -508,18 +509,41 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
func
getSelectorFromObject
(
obj
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
{
switch
typed
:=
obj
.
(
type
)
{
case
*
v1
.
ReplicationController
:
return
typed
.
Spec
.
Selector
,
nil
case
*
v1beta1
.
ReplicaSet
:
case
*
extv1beta1
.
ReplicaSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
v1beta1
.
Deploymen
t
:
case
*
appsv1
.
ReplicaSe
t
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
v1beta1
.
DaemonSet
:
case
*
extv1beta1
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
appsv1beta1
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
appsv1beta2
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
appsv1
.
Deployment
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
extv1beta1
.
DaemonSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
appsv1beta2
.
DaemonSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
appsv1
.
DaemonSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
batch
.
Job
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
apps
.
StatefulSet
:
case
*
appsv1beta1
.
StatefulSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
appsv1beta2
.
StatefulSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
case
*
appsv1
.
StatefulSet
:
return
typed
.
Spec
.
Selector
.
MatchLabels
,
nil
default
:
return
nil
,
fmt
.
Errorf
(
"Unsupported kind when getting selector: %v"
,
obj
)
}
...
...
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