@@ -52,12 +52,12 @@ type Installer interface {
52
52
type installer struct {
53
53
storageBackend * storage.Storage
54
54
tillerKubeClient * kube.Client
55
- chartDir string
55
+ chart * cpb. Chart
56
56
}
57
57
58
58
// NewInstaller returns a new Helm installer capable of installing and uninstalling releases.
59
- func NewInstaller (storageBackend * storage.Storage , tillerKubeClient * kube.Client , chartDir string ) Installer {
60
- return installer {storageBackend , tillerKubeClient , chartDir }
59
+ func NewInstaller (storageBackend * storage.Storage , tillerKubeClient * kube.Client , chart * cpb. Chart ) Installer {
60
+ return installer {storageBackend , tillerKubeClient , chart }
61
61
}
62
62
63
63
// NewInstallerFromEnv returns a GVK and installer based on configuration provided
@@ -73,7 +73,30 @@ func NewInstallerFromEnv(storageBackend *storage.Storage, tillerKubeClient *kube
73
73
return gvk , nil , err
74
74
}
75
75
gvk = gv .WithKind (kind )
76
- installer := NewInstaller (storageBackend , tillerKubeClient , chartDir )
76
+
77
+ // Verify the GVK. In general, GVKs without groups are valid. However,
78
+ // a GVK without a group will most likely fail with a more descriptive
79
+ // error later in the initialization process.
80
+ if gvk .Version == "" {
81
+ return gvk , nil , fmt .Errorf ("invalid %s: version must not be empty" , APIVersionEnvVar )
82
+ }
83
+ if gvk .Kind == "" {
84
+ return gvk , nil , fmt .Errorf ("invalid %s: kind must not be empty" , KindEnvVar )
85
+ }
86
+
87
+ // Verify that the Helm chart directory is valid.
88
+ if chartDir == "" {
89
+ return gvk , nil , fmt .Errorf ("invalid %s: must not be empty" , HelmChartEnvVar )
90
+ }
91
+ if stat , err := os .Stat (chartDir ); err != nil || ! stat .IsDir () {
92
+ return gvk , nil , fmt .Errorf ("invalid %s: %s is not a directory" , HelmChartEnvVar , chartDir )
93
+ }
94
+ chart , err := chartutil .LoadDir (chartDir )
95
+ if err != nil {
96
+ return gvk , nil , fmt .Errorf ("invalid %s: failed loading chart from %s: %s" , HelmChartEnvVar , chartDir , err )
97
+ }
98
+
99
+ installer := NewInstaller (storageBackend , tillerKubeClient , chart )
77
100
return gvk , installer , nil
78
101
}
79
102
@@ -86,11 +109,6 @@ func (c installer) InstallRelease(r *v1alpha1.HelmApp) (*v1alpha1.HelmApp, error
86
109
return r , err
87
110
}
88
111
89
- chart , err := chartutil .LoadDir (c .chartDir )
90
- if err != nil {
91
- return r , err
92
- }
93
-
94
112
var updatedRelease * release.Release
95
113
latestRelease , err := c .storageBackend .Last (releaseName (r ))
96
114
@@ -101,7 +119,7 @@ func (c installer) InstallRelease(r *v1alpha1.HelmApp) (*v1alpha1.HelmApp, error
101
119
installReq := & services.InstallReleaseRequest {
102
120
Namespace : r .GetNamespace (),
103
121
Name : releaseName (r ),
104
- Chart : chart ,
122
+ Chart : c . chart ,
105
123
Values : & cpb.Config {Raw : string (cr )},
106
124
}
107
125
@@ -118,7 +136,7 @@ func (c installer) InstallRelease(r *v1alpha1.HelmApp) (*v1alpha1.HelmApp, error
118
136
} else {
119
137
updateReq := & services.UpdateReleaseRequest {
120
138
Name : releaseName (r ),
121
- Chart : chart ,
139
+ Chart : c . chart ,
122
140
Values : & cpb.Config {Raw : string (cr )},
123
141
}
124
142
0 commit comments