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
55fbed95
Unverified
Commit
55fbed95
authored
Mar 04, 2019
by
Jacob LeGrone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(resource-policy): delete manifests when policy value is delete
Signed-off-by:
Jacob LeGrone
<
git@jacob.work
>
parent
33589472
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
16 deletions
+27
-16
client.go
pkg/kube/client.go
+5
-3
resource_policy.go
pkg/kube/resource_policy.go
+19
-4
resource_policy.go
pkg/tiller/resource_policy.go
+3
-9
No files found.
pkg/kube/client.go
View file @
55fbed95
...
@@ -23,12 +23,13 @@ import (
...
@@ -23,12 +23,13 @@ import (
goerrors
"errors"
goerrors
"errors"
"fmt"
"fmt"
"io"
"io"
"k8s.io/apimachinery/pkg/api/meta"
"log"
"log"
"sort"
"sort"
"strings"
"strings"
"time"
"time"
"k8s.io/apimachinery/pkg/api/meta"
"github.com/evanphx/json-patch"
"github.com/evanphx/json-patch"
appsv1
"k8s.io/api/apps/v1"
appsv1
"k8s.io/api/apps/v1"
appsv1beta1
"k8s.io/api/apps/v1beta1"
appsv1beta1
"k8s.io/api/apps/v1beta1"
...
@@ -362,8 +363,9 @@ func (c *Client) Update(namespace string, originalReader, targetReader io.Reader
...
@@ -362,8 +363,9 @@ func (c *Client) Update(namespace string, originalReader, targetReader io.Reader
if
err
!=
nil
{
if
err
!=
nil
{
c
.
Log
(
"Unable to get annotations on %q, err: %s"
,
info
.
Name
,
err
)
c
.
Log
(
"Unable to get annotations on %q, err: %s"
,
info
.
Name
,
err
)
}
}
if
annotations
!=
nil
&&
annotations
[
ResourcePolicyAnno
]
==
KeepPolicy
{
if
ResourcePolicyIsKeep
(
annotations
)
{
c
.
Log
(
"Skipping delete of %q due to annotation [%s=%s]"
,
info
.
Name
,
ResourcePolicyAnno
,
KeepPolicy
)
policy
:=
annotations
[
ResourcePolicyAnno
]
c
.
Log
(
"Skipping delete of %q due to annotation [%s=%s]"
,
info
.
Name
,
ResourcePolicyAnno
,
policy
)
continue
continue
}
}
...
...
pkg/kube/resource_policy.go
View file @
55fbed95
...
@@ -19,8 +19,23 @@ package kube
...
@@ -19,8 +19,23 @@ package kube
// ResourcePolicyAnno is the annotation name for a resource policy
// ResourcePolicyAnno is the annotation name for a resource policy
const
ResourcePolicyAnno
=
"helm.sh/resource-policy"
const
ResourcePolicyAnno
=
"helm.sh/resource-policy"
//
KeepPolicy is the resource policy type for keep
//
deletePolicy is the resource policy type for delete
//
//
// This resource policy type allows resources to skip being deleted
// This resource policy type allows explicitly opting in to the default
// during an uninstallRelease action.
// resource deletion behavior, for example when overriding a chart's
const
KeepPolicy
=
"keep"
// default annotations. Any other value allows resources to skip being
// deleted during an uninstallRelease action.
const
deletePolicy
=
"delete"
// ResourcePolicyIsKeep accepts a map of Kubernetes resource annotations and
// returns true if the resource should be kept, otherwise false if it is safe
// for Helm to delete.
func
ResourcePolicyIsKeep
(
annotations
map
[
string
]
string
)
bool
{
if
annotations
!=
nil
{
resourcePolicyType
,
ok
:=
annotations
[
ResourcePolicyAnno
]
if
ok
&&
resourcePolicyType
!=
deletePolicy
{
return
true
}
}
return
false
}
pkg/tiller/resource_policy.go
View file @
55fbed95
...
@@ -34,17 +34,11 @@ func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) {
...
@@ -34,17 +34,11 @@ func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) {
continue
continue
}
}
resourcePolicyType
,
ok
:=
m
.
Head
.
Metadata
.
Annotations
[
kube
.
ResourcePolicyAnno
]
if
kube
.
ResourcePolicyIsKeep
(
m
.
Head
.
Metadata
.
Annotations
)
{
if
!
ok
{
remaining
=
append
(
remaining
,
m
)
continue
}
resourcePolicyType
=
strings
.
ToLower
(
strings
.
TrimSpace
(
resourcePolicyType
))
if
resourcePolicyType
==
kube
.
KeepPolicy
{
keep
=
append
(
keep
,
m
)
keep
=
append
(
keep
,
m
)
}
else
{
remaining
=
append
(
remaining
,
m
)
}
}
}
}
return
keep
,
remaining
return
keep
,
remaining
}
}
...
...
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