Skip to content

Commit 99775c1

Browse files
authored
Merge pull request #2 from alauda/dep
Sync vendor with helm
2 parents c482cfd + bc3b165 commit 99775c1

38 files changed

+898
-811
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ replace k8s.io/apiserver => k8s.io/apiserver v0.0.0-20190606205144-71ebb8303503
1010

1111
replace sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-beta.3
1212

13-
replace helm.sh/helm => github.com/alauda/helm v3.0.0-alpha.1.0.20190717063003-edacb2027b32+incompatible
13+
replace helm.sh/helm => github.com/alauda/helm v3.0.0-alpha.1.0.20190806070809-af9bbccc4ffd+incompatible
1414

1515
replace github.com/russross/blackfriday => github.com/russross/blackfriday v1.5.2
1616

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/O
2828
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
2929
github.com/alauda/component-base v0.0.0-20190628064654-a4dafcfd3446 h1:gtzuHCPURUuSWz5y/gkLQyxJn/W3pqG74YpzghVG7bY=
3030
github.com/alauda/component-base v0.0.0-20190628064654-a4dafcfd3446/go.mod h1:tbaXeIWDl6zX1b7O53FSXClDS1YmEDRnVJszgcLXzpk=
31-
github.com/alauda/helm v3.0.0-alpha.1.0.20190717063003-edacb2027b32+incompatible h1:We5tz23uKFPNkSycXS/Yi4jgtEveq9mvqBRrOsNhKfY=
32-
github.com/alauda/helm v3.0.0-alpha.1.0.20190717063003-edacb2027b32+incompatible/go.mod h1:puN71hQ/dtLbcyDOPyhZw19FrLSYCak3EvJBT2OaRvQ=
31+
github.com/alauda/helm v3.0.0-alpha.1.0.20190806070809-af9bbccc4ffd+incompatible h1:QVylONSBF3PZQrgMOa36qfPFFh/yfRl5wn7tQIzqO2o=
32+
github.com/alauda/helm v3.0.0-alpha.1.0.20190806070809-af9bbccc4ffd+incompatible/go.mod h1:puN71hQ/dtLbcyDOPyhZw19FrLSYCak3EvJBT2OaRvQ=
3333
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3434
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
3535
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=

pkg/helm/config.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ func newActionConfig(info *cluster.Info) (*action.Configuration, error) {
8181
// hope it works
8282
kc.Log = klog.Infof
8383

84-
clientset, err := kc.KubernetesClientSet()
85-
if err != nil {
86-
return nil, err
87-
}
88-
8984
namespace := getNamespace(cfgFlags)
9085

9186
relClientSet, err := releaseclient.NewForConfig(info.ToRestConfig())
@@ -99,14 +94,6 @@ func newActionConfig(info *cluster.Info) (*action.Configuration, error) {
9994
d := storagedriver.NewReleases(relClientSet.AppV1alpha1().Releases(namespace))
10095
d.Log = klog.Infof
10196
store = storage.Init(d)
102-
case "secret", "secrets":
103-
d := driver.NewSecrets(clientset.CoreV1().Secrets(namespace))
104-
d.Log = klog.Infof
105-
store = storage.Init(d)
106-
case "configmap", "configmaps":
107-
d := driver.NewConfigMaps(clientset.CoreV1().ConfigMaps(namespace))
108-
d.Log = klog.Infof
109-
store = storage.Init(d)
11097
case "memory":
11198
d := driver.NewMemory()
11299
store = storage.Init(d)

pkg/kube/client.go

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package kube
22

33
import (
4-
"bytes"
5-
"io"
6-
"io/ioutil"
7-
84
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
95
"k8s.io/client-go/kubernetes/scheme"
106

@@ -36,45 +32,17 @@ func New(getter genericclioptions.RESTClientGetter) *Client {
3632
}
3733
}
3834

39-
// BuildUnstructured validates for Kubernetes objects and returns unstructured infos.
40-
// Maybe this override is not needed anymore
41-
func (c *Client) BuildUnstructured(reader io.Reader) (kube.Result, error) {
42-
result, err := c.Client.BuildUnstructured(reader)
43-
if err != nil {
44-
klog.Warning("build unstructured error: ", err)
45-
return result, err
46-
47-
// if strings.Contains(err.Error(), "apiVersion") && strings.Contains(err.Error(), "is not available") {
48-
// klog.Warning("encountered apiVersion not found it, ignore it: ", err)
49-
// return result, nil
50-
// }
51-
}
52-
return result, err
53-
}
54-
55-
// Build validates for Kubernetes objects and returns resource Infos from a io.Reader.
56-
func (c *Client) Build(reader io.Reader) (kube.Result, error) {
57-
return c.Client.BuildUnstructured(reader)
58-
}
59-
6035
// Create plan to support replace.... hold on...
61-
func (c *Client) Create(reader io.Reader) error {
62-
buf, err := ioutil.ReadAll(reader)
63-
if err != nil {
64-
return err
65-
}
36+
func (c *Client) Create(resources kube.ResourceList) (*kube.Result, error) {
6637

67-
create := bytes.NewBuffer(buf)
68-
origin := bytes.NewBuffer(buf)
69-
target := bytes.NewBuffer(buf)
70-
71-
if err := c.Client.Create(create); err != nil {
38+
result, err := c.Client.Create(resources)
39+
if err != nil {
7240
klog.Warning("create resource error:", err)
7341
if errors.IsAlreadyExists(err) {
7442
klog.Warningf("create error due to resource exist, do a dumb update...")
75-
return c.Client.Update(origin, target, true, false)
43+
return c.Client.Update(resources, resources, true)
7644
}
77-
return err
45+
return result, err
7846
}
79-
return nil
47+
return result, nil
8048
}

vendor/helm.sh/helm/pkg/action/action.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@ limitations under the License.
1717
package action
1818

1919
import (
20+
"bytes"
2021
"path"
2122
"regexp"
23+
"sort"
24+
"strings"
2225
"time"
2326

2427
"github.com/pkg/errors"
2528
"k8s.io/apimachinery/pkg/api/meta"
2629
"k8s.io/client-go/discovery"
30+
"k8s.io/client-go/kubernetes"
2731
"k8s.io/client-go/rest"
2832

2933
"helm.sh/helm/pkg/chartutil"
34+
"helm.sh/helm/pkg/hooks"
3035
"helm.sh/helm/pkg/kube"
3136
"helm.sh/helm/pkg/registry"
3237
"helm.sh/helm/pkg/release"
@@ -110,6 +115,15 @@ func (c *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
110115
return c.Capabilities, nil
111116
}
112117

118+
func (c *Configuration) KubernetesClientSet() (kubernetes.Interface, error) {
119+
conf, err := c.RESTClientGetter.ToRESTConfig()
120+
if err != nil {
121+
return nil, errors.Wrap(err, "unable to generate config for kubernetes client")
122+
}
123+
124+
return kubernetes.NewForConfig(conf)
125+
}
126+
113127
// Now generates a timestamp
114128
//
115129
// If the configuration has a Timestamper on it, that will be used.
@@ -190,3 +204,73 @@ type RESTClientGetter interface {
190204
ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
191205
ToRESTMapper() (meta.RESTMapper, error)
192206
}
207+
208+
// execHooks is a method for exec-ing all hooks of the given type. This is to
209+
// avoid duplicate code in various actions
210+
func execHooks(client kube.Interface, hs []*release.Hook, hook string, timeout time.Duration) error {
211+
executingHooks := []*release.Hook{}
212+
213+
for _, h := range hs {
214+
for _, e := range h.Events {
215+
if string(e) == hook {
216+
executingHooks = append(executingHooks, h)
217+
}
218+
}
219+
}
220+
221+
sort.Sort(hookByWeight(executingHooks))
222+
for _, h := range executingHooks {
223+
if err := deleteHookByPolicy(client, h, hooks.BeforeHookCreation); err != nil {
224+
return err
225+
}
226+
227+
resources, err := client.Build(bytes.NewBufferString(h.Manifest))
228+
if err != nil {
229+
return errors.Wrapf(err, "unable to build kubernetes object for %s hook %s", hook, h.Path)
230+
}
231+
if _, err := client.Create(resources); err != nil {
232+
return errors.Wrapf(err, "warning: Hook %s %s failed", hook, h.Path)
233+
}
234+
235+
if err := client.WatchUntilReady(resources, timeout); err != nil {
236+
// If a hook is failed, checkout the annotation of the hook to determine whether the hook should be deleted
237+
// under failed condition. If so, then clear the corresponding resource object in the hook
238+
if err := deleteHookByPolicy(client, h, hooks.HookFailed); err != nil {
239+
return err
240+
}
241+
return err
242+
}
243+
}
244+
245+
// If all hooks are succeeded, checkout the annotation of each hook to determine whether the hook should be deleted
246+
// under succeeded condition. If so, then clear the corresponding resource object in each hook
247+
for _, h := range executingHooks {
248+
if err := deleteHookByPolicy(client, h, hooks.HookSucceeded); err != nil {
249+
return err
250+
}
251+
h.LastRun = time.Now()
252+
}
253+
254+
return nil
255+
}
256+
257+
// deleteHookByPolicy deletes a hook if the hook policy instructs it to
258+
func deleteHookByPolicy(client kube.Interface, h *release.Hook, policy string) error {
259+
if hookHasDeletePolicy(h, policy) {
260+
resources, err := client.Build(bytes.NewBufferString(h.Manifest))
261+
if err != nil {
262+
return errors.Wrapf(err, "unable to build kubernetes object for deleting hook %s", h.Path)
263+
}
264+
_, errs := client.Delete(resources)
265+
return errors.New(joinErrors(errs))
266+
}
267+
return nil
268+
}
269+
270+
func joinErrors(errs []error) string {
271+
es := make([]string, 0, len(errs))
272+
for _, e := range errs {
273+
es = append(es, e.Error())
274+
}
275+
return strings.Join(es, "; ")
276+
}

vendor/helm.sh/helm/pkg/action/chart_save.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ package action
1818

1919
import (
2020
"io"
21-
"path/filepath"
2221

23-
"helm.sh/helm/pkg/chart/loader"
22+
"helm.sh/helm/pkg/chart"
2423
"helm.sh/helm/pkg/registry"
2524
)
2625

@@ -37,20 +36,15 @@ func NewChartSave(cfg *Configuration) *ChartSave {
3736
}
3837

3938
// Run executes the chart save operation
40-
func (a *ChartSave) Run(out io.Writer, path, ref string) error {
41-
path, err := filepath.Abs(path)
42-
if err != nil {
43-
return err
44-
}
45-
46-
ch, err := loader.LoadDir(path)
39+
func (a *ChartSave) Run(out io.Writer, ch *chart.Chart, ref string) error {
40+
r, err := registry.ParseReference(ref)
4741
if err != nil {
4842
return err
4943
}
5044

51-
r, err := registry.ParseReference(ref)
52-
if err != nil {
53-
return err
45+
// If no tag is present, use the chart version
46+
if r.Tag == "" {
47+
r.Tag = ch.Metadata.Version
5448
}
5549

5650
return a.cfg.RegistryClient.SaveChart(ch, r)

0 commit comments

Comments
 (0)