@@ -349,10 +349,8 @@ func (o *CreateOrUpdateOptions) RunUpdate(args []string) error {
349
349
}
350
350
351
351
func (o CreateOrUpdateOptions ) update (client kubernetes.Interface , kcClient kcclient.Interface , pkgInstall * kcpkgv1alpha1.PackageInstall ) error {
352
- updatedPkgInstall , changed , err := o .preparePackageInstallForUpdate (pkgInstall )
353
- if err != nil {
354
- return err
355
- }
352
+ changed := o .version != "" && o .version != pkgInstall .Spec .PackageRef .VersionSelection .Constraints
353
+ updatedPkgInstall := pkgInstall .DeepCopy ()
356
354
357
355
switch {
358
356
case changed : // Continue if package install resource is changed
@@ -370,7 +368,7 @@ func (o CreateOrUpdateOptions) update(client kubernetes.Interface, kcClient kccl
370
368
reconciliationPaused := false
371
369
if (o .valuesFile != "" && len (pkgInstall .Spec .Values ) > 0 ) ||
372
370
(len (o .YttOverlayFlags .yttOverlayFiles ) > 0 && hasYttOverlays (pkgInstall )) {
373
- updatedPkgInstall , err = o .pauseReconciliation (kcClient )
371
+ _ , err : = o .pauseReconciliation (kcClient )
374
372
if err != nil {
375
373
return err
376
374
}
@@ -379,6 +377,20 @@ func (o CreateOrUpdateOptions) update(client kubernetes.Interface, kcClient kccl
379
377
return err
380
378
}
381
379
reconciliationPaused = true
380
+
381
+ // observedGeneration is updated after pausing reconciliation
382
+ updatedPkgInstall , err = kcClient .PackagingV1alpha1 ().PackageInstalls (o .NamespaceFlags .Name ).Get (
383
+ context .Background (), o .Name , metav1.GetOptions {},
384
+ )
385
+ if err != nil {
386
+ return err
387
+ }
388
+ }
389
+
390
+ var err error
391
+ updatedPkgInstall , err = o .preparePackageInstallForUpdate (updatedPkgInstall )
392
+ if err != nil {
393
+ return err
382
394
}
383
395
384
396
isSecretCreated , err := o .createOrUpdateValuesSecret (updatedPkgInstall , client )
@@ -734,40 +746,32 @@ func (o *CreateOrUpdateOptions) createOrUpdateServiceAccount(client kubernetes.I
734
746
return true , nil
735
747
}
736
748
737
- func (o * CreateOrUpdateOptions ) preparePackageInstallForUpdate (pkgInstall * kcpkgv1alpha1.PackageInstall ) (* kcpkgv1alpha1.PackageInstall , bool , error ) {
738
- var (
739
- changed bool
740
- err error
741
- )
742
-
749
+ func (o * CreateOrUpdateOptions ) preparePackageInstallForUpdate (pkgInstall * kcpkgv1alpha1.PackageInstall ) (* kcpkgv1alpha1.PackageInstall , error ) {
743
750
updatedPkgInstall := pkgInstall .DeepCopy ()
744
751
745
752
if updatedPkgInstall .Spec .PackageRef == nil || updatedPkgInstall .Spec .PackageRef .VersionSelection == nil {
746
- err = fmt .Errorf ("Failed to update package '%s' as no existing package reference/version was found in the package install" , o .Name )
747
- return nil , false , err
753
+ return nil , fmt .Errorf ("Failed to update package '%s' as no existing package reference/version was found in the package install" , o .Name )
748
754
}
749
755
750
756
// If o.PackageName is provided by the user (via --package flag), verify that the package name in PackageInstall matches it.
751
757
// This will prevent the users from accidentally overwriting an installed package with another package content due to choosing a pre-existing name for the package isntall.
752
758
// Otherwise if o.PackageName is not provided, fill it from the installed package spec
753
759
if o .packageName != "" && updatedPkgInstall .Spec .PackageRef .RefName != o .packageName {
754
- err = fmt .Errorf ("Installed package '%s' is already associated with package '%s'" , o .Name , updatedPkgInstall .Spec .PackageRef .RefName )
755
- return nil , false , err
760
+ return nil , fmt .Errorf ("Installed package '%s' is already associated with package '%s'" , o .Name , updatedPkgInstall .Spec .PackageRef .RefName )
756
761
}
757
762
o .packageName = updatedPkgInstall .Spec .PackageRef .RefName
758
763
759
764
// If o.Version is provided by the user (via --version flag), set the version in PackageInstall to this version
760
765
// Otherwise if o.Version is not provided, fill it from the installed package spec
761
766
if o .version != "" {
762
767
if updatedPkgInstall .Spec .PackageRef .VersionSelection .Constraints != o .version {
763
- changed = true
764
768
updatedPkgInstall .Spec .PackageRef .VersionSelection .Constraints = o .version
765
769
}
766
770
} else {
767
771
o .version = updatedPkgInstall .Spec .PackageRef .VersionSelection .Constraints
768
772
}
769
773
770
- return updatedPkgInstall , changed , nil
774
+ return updatedPkgInstall , nil
771
775
}
772
776
773
777
func (o * CreateOrUpdateOptions ) createOrUpdateValuesSecret (pkgInstallToUpdate * kcpkgv1alpha1.PackageInstall , client kubernetes.Interface ) (bool , error ) {
0 commit comments