@@ -32,10 +32,11 @@ import (
32
32
apierrors "k8s.io/apimachinery/pkg/api/errors"
33
33
"k8s.io/apimachinery/pkg/runtime/schema"
34
34
"sigs.k8s.io/controller-runtime/pkg/client"
35
+ "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
35
36
"sigs.k8s.io/yaml"
36
37
37
38
"github.com/fluxcd/cli-utils/pkg/object"
38
- helmv2 "github.com/fluxcd/helm-controller/api/v2beta1 "
39
+ helmv2 "github.com/fluxcd/helm-controller/api/v2beta2 "
39
40
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
40
41
"github.com/fluxcd/pkg/ssa"
41
42
@@ -208,27 +209,16 @@ func getHelmReleaseInventory(ctx context.Context, objectKey client.ObjectKey, ku
208
209
return nil , nil
209
210
}
210
211
211
- storageNamespace := hr .GetNamespace ()
212
- if hr .Spec .StorageNamespace != "" {
213
- storageNamespace = hr .Spec .StorageNamespace
214
- }
215
-
216
- storageName := hr .GetName ()
217
- if hr .Spec .ReleaseName != "" {
218
- storageName = hr .Spec .ReleaseName
219
- } else if hr .Spec .TargetNamespace != "" {
220
- storageName = strings .Join ([]string {hr .Spec .TargetNamespace , hr .Name }, "-" )
221
- }
222
-
223
- storageVersion := hr .Status .LastReleaseRevision
224
- // skip release if it failed to install
225
- if storageVersion < 1 {
212
+ storageNamespace := hr .Status .StorageNamespace
213
+ latest := hr .Status .History .Latest ()
214
+ if len (storageNamespace ) == 0 || latest == nil {
215
+ // Skip release if it has no current
226
216
return nil , nil
227
217
}
228
218
229
219
storageKey := client.ObjectKey {
230
220
Namespace : storageNamespace ,
231
- Name : fmt .Sprintf ("sh.helm.release.v1.%s.v%v" , storageName , storageVersion ),
221
+ Name : fmt .Sprintf ("sh.helm.release.v1.%s.v%v" , latest . Name , latest . Version ),
232
222
}
233
223
234
224
storageSecret := & corev1.Secret {}
@@ -279,12 +269,8 @@ func getHelmReleaseInventory(ctx context.Context, objectKey client.ObjectKey, ku
279
269
// set the namespace on namespaced objects
280
270
for _ , obj := range objects {
281
271
if obj .GetNamespace () == "" {
282
- if isNamespaced , _ := utils .IsAPINamespaced (obj , kubeClient .Scheme (), kubeClient .RESTMapper ()); isNamespaced {
283
- if hr .Spec .TargetNamespace != "" {
284
- obj .SetNamespace (hr .Spec .TargetNamespace )
285
- } else {
286
- obj .SetNamespace (hr .GetNamespace ())
287
- }
272
+ if isNamespaced , _ := apiutil .IsObjectNamespaced (obj , kubeClient .Scheme (), kubeClient .RESTMapper ()); isNamespaced {
273
+ obj .SetNamespace (latest .Namespace )
288
274
}
289
275
}
290
276
}
0 commit comments