@ -572,7 +572,7 @@ func (c *Client) BuildTable(reader io.Reader, validate bool) (ResourceList, erro
transformRequests )
transformRequests )
}
}
func ( c * Client ) update ( originals , targets ResourceList , createApplyFunc CreateApplyFunc , updateApplyFunc UpdateApplyFunc ) ( * Result , error ) {
func ( c * Client ) update ( originals , targets ResourceList , createApplyFunc CreateApplyFunc , updateApplyFunc UpdateApplyFunc , releaseName , releaseNamespace string ) ( * Result , error ) {
updateErrors := [ ] error { }
updateErrors := [ ] error { }
res := & Result { }
res := & Result { }
@ -681,6 +681,21 @@ func (c *Client) update(originals, targets ResourceList, createApplyFunc CreateA
c . Logger ( ) . Debug ( "skipping delete due to annotation" , "namespace" , info . Namespace , "name" , info . Name , "kind" , info . Mapping . GroupVersionKind . Kind , "annotation" , ResourcePolicyAnno , "value" , KeepPolicy )
c . Logger ( ) . Debug ( "skipping delete due to annotation" , "namespace" , info . Namespace , "name" , info . Name , "kind" , info . Mapping . GroupVersionKind . Kind , "annotation" , ResourcePolicyAnno , "value" , KeepPolicy )
continue
continue
}
}
if releaseName != "" && annotations != nil {
annoReleaseName := annotations [ ReleaseNameAnnotation ]
annoReleaseNS := annotations [ ReleaseNamespaceAnnotation ]
ownedByDifferentRelease := ( annoReleaseName != "" && annoReleaseName != releaseName ) ||
( releaseNamespace != "" && annoReleaseNS != "" && annoReleaseNS != releaseNamespace )
if ownedByDifferentRelease {
c . Logger ( ) . Warn ( "skipping delete of resource not owned by this release" ,
slog . String ( "namespace" , info . Namespace ) ,
slog . String ( "name" , info . Name ) ,
slog . String ( "kind" , info . Mapping . GroupVersionKind . Kind ) ,
slog . String ( "release" , releaseName ) ,
)
continue
}
}
if err := deleteResource ( info , metav1 . DeletePropagationBackground ) ; err != nil {
if err := deleteResource ( info , metav1 . DeletePropagationBackground ) ; err != nil {
c . Logger ( ) . Debug (
c . Logger ( ) . Debug (
"failed to delete resource" ,
"failed to delete resource" ,
@ -713,6 +728,8 @@ type clientUpdateOptions struct {
dryRun bool
dryRun bool
fieldValidationDirective FieldValidationDirective
fieldValidationDirective FieldValidationDirective
upgradeClientSideFieldManager bool
upgradeClientSideFieldManager bool
releaseName string
releaseNamespace string
}
}
type ClientUpdateOption func ( * clientUpdateOptions ) error
type ClientUpdateOption func ( * clientUpdateOptions ) error
@ -796,6 +813,22 @@ func ClientUpdateOptionUpgradeClientSideFieldManager(upgradeClientSideFieldManag
}
}
}
}
// ClientUpdateOptionOwnership specifies the release name and namespace that owns the resources being updated.
// When set, orphaned resources (present in the original list but not in the target list) will only be deleted
// if their meta.helm.sh/release-name and meta.helm.sh/release-namespace annotations match the specified
// release. Resources annotated as belonging to a different release will be skipped.
func ClientUpdateOptionOwnership ( releaseName , releaseNamespace string ) ClientUpdateOption {
return func ( o * clientUpdateOptions ) error {
if releaseName == "" {
return errors . New ( "releaseName must not be empty for ownership check" )
}
o . releaseName = releaseName
o . releaseNamespace = releaseNamespace
return nil
}
}
// Update takes the current list of objects and target list of objects and
// Update takes the current list of objects and target list of objects and
// creates resources that don't already exist, updates resources that have been
// creates resources that don't already exist, updates resources that have been
// modified in the target configuration, and deletes resources from the current
// modified in the target configuration, and deletes resources from the current
@ -902,7 +935,7 @@ func (c *Client) Update(originals, targets ResourceList, options ...ClientUpdate
}
}
}
}
return c . update ( originals , targets , createApplyFunc , makeUpdateApplyFunc ( ) )
return c . update ( originals , targets , createApplyFunc , makeUpdateApplyFunc ( ) , updateOptions . releaseName , updateOptions . releaseNamespace )
}
}
// Delete deletes Kubernetes resources specified in the resources list with
// Delete deletes Kubernetes resources specified in the resources list with