diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 3d577a92b5f9c..3c5a464c25558 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -349,6 +349,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { var ( revision string + prune bool dryRun bool ) var command = &cobra.Command{ @@ -366,6 +367,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co Name: appName, DryRun: dryRun, Revision: revision, + Prune: prune, } syncRes, err := appIf.Sync(context.Background(), &syncReq) errors.CheckError(err) @@ -379,6 +381,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co }, } command.Flags().BoolVar(&dryRun, "dry-run", false, "Preview apply without affecting cluster") + command.Flags().BoolVar(&prune, "prune", false, "Allow deleting unexpected resources") command.Flags().StringVar(&revision, "revision", "", "Sync to a specific revision. Preserves parameter overrides") return command } @@ -460,6 +463,9 @@ func paramString(params []argoappv1.ComponentParameter) string { // NewApplicationRollbackCommand returns a new instance of an `argocd app rollback` command func NewApplicationRollbackCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { + var ( + prune bool + ) var command = &cobra.Command{ Use: "rollback", Short: "Rollback application to a previous deployed version", @@ -487,8 +493,9 @@ func NewApplicationRollbackCommand(clientOpts *argocdclient.ClientOptions) *cobr log.Fatalf("Application '%s' does not have deployment id '%d' in history\n", app.ObjectMeta.Name, depID) } syncRes, err := appIf.Rollback(ctx, &application.ApplicationRollbackRequest{ - Name: appName, - ID: int64(depID), + Name: appName, + ID: int64(depID), + Prune: prune, }) errors.CheckError(err) fmt.Printf("%s %s\n", appName, syncRes.Message) @@ -500,5 +507,6 @@ func NewApplicationRollbackCommand(clientOpts *argocdclient.ClientOptions) *cobr _ = w.Flush() }, } + command.Flags().BoolVar(&prune, "prune", false, "Allow deleting unexpected resources") return command } diff --git a/server/application/application.go b/server/application/application.go index 5b06119d2c8af..e1e25424c41a2 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -6,7 +6,10 @@ import ( "strings" "time" + "encoding/json" + "github.com/argoproj/argo-cd/common" + "github.com/argoproj/argo-cd/controller" appv1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" appclientset "github.com/argoproj/argo-cd/pkg/client/clientset/versioned" "github.com/argoproj/argo-cd/reposerver" @@ -15,7 +18,6 @@ import ( apirepository "github.com/argoproj/argo-cd/server/repository" "github.com/argoproj/argo-cd/util" argoutil "github.com/argoproj/argo-cd/util/argo" - "github.com/argoproj/argo-cd/util/diff" "github.com/argoproj/argo-cd/util/git" "github.com/argoproj/argo-cd/util/kube" log "github.com/sirupsen/logrus" @@ -43,6 +45,7 @@ type Server struct { // TODO(jessesuen): move common cluster code to shared libraries clusterService cluster.ClusterServiceServer repoService apirepository.RepositoryServiceServer + appComparator controller.AppComparator } // NewServer returns a new instance of the Application service @@ -61,6 +64,7 @@ func NewServer( clusterService: clusterService, repoClientset: repoClientset, repoService: repoService, + appComparator: controller.NewKsonnetAppComparator(clusterService), } } @@ -334,7 +338,7 @@ func (s *Server) PodLogs(q *PodLogsQuery, ws ApplicationService_PodLogsServer) e // Sync syncs an application to its target state func (s *Server) Sync(ctx context.Context, syncReq *ApplicationSyncRequest) (*ApplicationSyncResult, error) { - return s.deployAndPersistDeploymentInfo(ctx, syncReq.Name, syncReq.Revision, nil, syncReq.DryRun) + return s.deployAndPersistDeploymentInfo(ctx, syncReq.Name, syncReq.Revision, nil, syncReq.DryRun, syncReq.Prune) } func (s *Server) Rollback(ctx context.Context, rollbackReq *ApplicationRollbackRequest) (*ApplicationSyncResult, error) { @@ -352,11 +356,11 @@ func (s *Server) Rollback(ctx context.Context, rollbackReq *ApplicationRollbackR if deploymentInfo == nil { return nil, status.Errorf(codes.InvalidArgument, "application %s does not have deployment with id %v", rollbackReq.Name, rollbackReq.ID) } - return s.deployAndPersistDeploymentInfo(ctx, rollbackReq.Name, deploymentInfo.Revision, &deploymentInfo.ComponentParameterOverrides, rollbackReq.DryRun) + return s.deployAndPersistDeploymentInfo(ctx, rollbackReq.Name, deploymentInfo.Revision, &deploymentInfo.ComponentParameterOverrides, rollbackReq.DryRun, rollbackReq.Prune) } func (s *Server) deployAndPersistDeploymentInfo( - ctx context.Context, appName string, revision string, overrides *[]appv1.ComponentParameter, dryRun bool) (*ApplicationSyncResult, error) { + ctx context.Context, appName string, revision string, overrides *[]appv1.ComponentParameter, dryRun bool, prune bool) (*ApplicationSyncResult, error) { log.Infof("Syncing application %s", appName) app, err := s.Get(ctx, &ApplicationQuery{Name: appName}) @@ -372,7 +376,7 @@ func (s *Server) deployAndPersistDeploymentInfo( app.Spec.Source.ComponentParameterOverrides = *overrides } - res, manifest, err := s.deploy(ctx, app.Spec.Source, app.Spec.Destination, app.Name, dryRun) + res, manifest, err := s.deploy(ctx, app, dryRun, prune) if err != nil { return nil, err } @@ -470,43 +474,35 @@ func (s *Server) getRepo(ctx context.Context, repoURL string) *appv1.Repository func (s *Server) deploy( ctx context.Context, - source appv1.ApplicationSource, - destination *appv1.ApplicationDestination, - appLabel string, - dryRun bool) (*ApplicationSyncResult, *repository.ManifestResponse, error) { + app *appv1.Application, + dryRun bool, + prune bool) (*ApplicationSyncResult, *repository.ManifestResponse, error) { - repo := s.getRepo(ctx, source.RepoURL) + repo := s.getRepo(ctx, app.Spec.Source.RepoURL) conn, repoClient, err := s.repoClientset.NewRepositoryClient() if err != nil { return nil, nil, err } defer util.Close(conn) - overrides := make([]*appv1.ComponentParameter, len(source.ComponentParameterOverrides)) - if source.ComponentParameterOverrides != nil { - for i := range source.ComponentParameterOverrides { - item := source.ComponentParameterOverrides[i] + overrides := make([]*appv1.ComponentParameter, len(app.Spec.Source.ComponentParameterOverrides)) + if app.Spec.Source.ComponentParameterOverrides != nil { + for i := range app.Spec.Source.ComponentParameterOverrides { + item := app.Spec.Source.ComponentParameterOverrides[i] overrides[i] = &item } } manifestInfo, err := repoClient.GenerateManifest(ctx, &repository.ManifestRequest{ Repo: repo, - Environment: source.Environment, - Path: source.Path, - Revision: source.TargetRevision, + Environment: app.Spec.Source.Environment, + Path: app.Spec.Source.Path, + Revision: app.Spec.Source.TargetRevision, ComponentParameterOverrides: overrides, - AppLabel: appLabel, + AppLabel: app.Name, }) if err != nil { return nil, nil, err } - server, namespace := argoutil.ResolveServerNamespace(destination, manifestInfo) - - clst, err := s.clusterService.Get(ctx, &cluster.ClusterQuery{Server: server}) - if err != nil { - return nil, nil, err - } - config := clst.RESTConfig() targetObjs := make([]*unstructured.Unstructured, len(manifestInfo.Manifests)) for i, manifest := range manifestInfo.Manifests { @@ -517,41 +513,89 @@ func (s *Server) deploy( targetObjs[i] = obj } - liveObjs, err := kube.GetLiveResources(config, targetObjs, namespace) + server, namespace := argoutil.ResolveServerNamespace(app.Spec.Destination, manifestInfo) + + comparison, err := s.appComparator.CompareAppState(server, namespace, targetObjs, app) if err != nil { return nil, nil, err } - diffResList, err := diff.DiffArray(targetObjs, liveObjs) + + clst, err := s.clusterService.Get(ctx, &cluster.ClusterQuery{Server: server}) if err != nil { return nil, nil, err } + config := clst.RESTConfig() var syncRes ApplicationSyncResult syncRes.Resources = make([]*ResourceDetails, 0) - for i, diffRes := range diffResList.Diffs { + for _, resourceState := range comparison.Resources { + var liveObj, targetObj *unstructured.Unstructured + + if resourceState.LiveState != "null" { + liveObj = &unstructured.Unstructured{} + err = json.Unmarshal([]byte(resourceState.LiveState), liveObj) + if err != nil { + return nil, nil, err + } + } + + if resourceState.TargetState != "null" { + targetObj = &unstructured.Unstructured{} + err = json.Unmarshal([]byte(resourceState.TargetState), targetObj) + if err != nil { + return nil, nil, err + } + } + + needsCreate := liveObj == nil + needsDelete := targetObj == nil + + obj := targetObj + if obj == nil { + obj = liveObj + } resDetails := ResourceDetails{ - Name: targetObjs[i].GetName(), - Kind: targetObjs[i].GetKind(), + Name: obj.GetName(), + Kind: obj.GetKind(), Namespace: namespace, } - needsCreate := bool(liveObjs[i] == nil) - if !diffRes.Modified { + + if resourceState.Status == appv1.ComparisonStatusSynced { resDetails.Message = fmt.Sprintf("already synced") } else if dryRun { if needsCreate { resDetails.Message = fmt.Sprintf("will create") + } else if needsDelete { + if prune { + resDetails.Message = fmt.Sprintf("will delete") + } else { + resDetails.Message = fmt.Sprintf("will be ignored (should be deleted)") + } } else { resDetails.Message = fmt.Sprintf("will update") } } else { - _, err := kube.ApplyResource(config, targetObjs[i], namespace) - if err != nil { - return nil, nil, err - } - if needsCreate { - resDetails.Message = fmt.Sprintf("created") + if needsDelete { + if prune { + err = kube.DeleteResource(config, liveObj, namespace) + if err != nil { + return nil, nil, err + } + + resDetails.Message = fmt.Sprintf("deleted") + } else { + resDetails.Message = fmt.Sprintf("ignored (should be deleted)") + } } else { - resDetails.Message = fmt.Sprintf("updated") + _, err := kube.ApplyResource(config, targetObj, namespace) + if err != nil { + return nil, nil, err + } + if needsCreate { + resDetails.Message = fmt.Sprintf("created") + } else { + resDetails.Message = fmt.Sprintf("updated") + } } } syncRes.Resources = append(syncRes.Resources, &resDetails) diff --git a/server/application/application.pb.go b/server/application/application.pb.go index 9797128871758..2c3f3931c5651 100644 --- a/server/application/application.pb.go +++ b/server/application/application.pb.go @@ -122,6 +122,7 @@ type ApplicationSyncRequest struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Revision string `protobuf:"bytes,2,opt,name=revision,proto3" json:"revision,omitempty"` DryRun bool `protobuf:"varint,3,opt,name=dryRun,proto3" json:"dryRun,omitempty"` + Prune bool `protobuf:"varint,4,opt,name=prune,proto3" json:"prune,omitempty"` } func (m *ApplicationSyncRequest) Reset() { *m = ApplicationSyncRequest{} } @@ -152,6 +153,13 @@ func (m *ApplicationSyncRequest) GetDryRun() bool { return false } +func (m *ApplicationSyncRequest) GetPrune() bool { + if m != nil { + return m.Prune + } + return false +} + // ApplicationSyncResult is a result of a sync requeswt type ApplicationSyncResult struct { Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` @@ -181,6 +189,7 @@ type ApplicationRollbackRequest struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` ID int64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` DryRun bool `protobuf:"varint,3,opt,name=dryRun,proto3" json:"dryRun,omitempty"` + Prune bool `protobuf:"varint,4,opt,name=prune,proto3" json:"prune,omitempty"` } func (m *ApplicationRollbackRequest) Reset() { *m = ApplicationRollbackRequest{} } @@ -211,6 +220,13 @@ func (m *ApplicationRollbackRequest) GetDryRun() bool { return false } +func (m *ApplicationRollbackRequest) GetPrune() bool { + if m != nil { + return m.Prune + } + return false +} + type ResourceDetails struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"` @@ -945,6 +961,16 @@ func (m *ApplicationSyncRequest) MarshalTo(dAtA []byte) (int, error) { } i++ } + if m.Prune { + dAtA[i] = 0x20 + i++ + if m.Prune { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } return i, nil } @@ -1020,6 +1046,16 @@ func (m *ApplicationRollbackRequest) MarshalTo(dAtA []byte) (int, error) { } i++ } + if m.Prune { + dAtA[i] = 0x20 + i++ + if m.Prune { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } return i, nil } @@ -1255,6 +1291,9 @@ func (m *ApplicationSyncRequest) Size() (n int) { if m.DryRun { n += 2 } + if m.Prune { + n += 2 + } return n } @@ -1287,6 +1326,9 @@ func (m *ApplicationRollbackRequest) Size() (n int) { if m.DryRun { n += 2 } + if m.Prune { + n += 2 + } return n } @@ -1777,6 +1819,26 @@ func (m *ApplicationSyncRequest) Unmarshal(dAtA []byte) error { } } m.DryRun = bool(v != 0) + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Prune", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApplication + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.Prune = bool(v != 0) default: iNdEx = preIndex skippy, err := skipApplication(dAtA[iNdEx:]) @@ -2005,6 +2067,26 @@ func (m *ApplicationRollbackRequest) Unmarshal(dAtA []byte) error { } } m.DryRun = bool(v != 0) + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Prune", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowApplication + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.Prune = bool(v != 0) default: iNdEx = preIndex skippy, err := skipApplication(dAtA[iNdEx:]) @@ -2748,67 +2830,67 @@ var ( func init() { proto.RegisterFile("server/application/application.proto", fileDescriptorApplication) } var fileDescriptorApplication = []byte{ - // 982 bytes of a gzipped FileDescriptorProto + // 990 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x41, 0x6f, 0xdc, 0x44, - 0x14, 0x96, 0x77, 0xb7, 0x9b, 0xec, 0xa4, 0xa2, 0x68, 0x48, 0x22, 0xd7, 0x4d, 0xd3, 0xd5, 0x34, - 0x85, 0x25, 0x08, 0xbb, 0x09, 0x20, 0x50, 0x54, 0x0e, 0x84, 0x14, 0x28, 0x8a, 0x50, 0x70, 0x8a, - 0x90, 0xb8, 0xd0, 0x89, 0xfd, 0xea, 0x98, 0xb5, 0x67, 0x5c, 0xcf, 0xec, 0xa2, 0xa5, 0xe4, 0x00, + 0x14, 0x96, 0x77, 0x37, 0x9b, 0xdd, 0x49, 0x45, 0xd1, 0x90, 0x44, 0xae, 0x9b, 0xa6, 0xab, 0x69, + 0x0a, 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0xee, 0xd0, 0x28, 0x39, 0xa5, 0x17, 0x5c, 0x91, - 0xe7, 0xd1, 0xb3, 0x6f, 0x95, 0x76, 0x1f, 0x0e, 0x20, 0x1d, 0x61, 0x8c, 0x5a, 0x8c, 0xc6, 0x60, - 0x1a, 0x5d, 0xa3, 0xd7, 0x71, 0xf5, 0x9a, 0xac, 0xa1, 0xe7, 0x2a, 0x76, 0x2e, 0x88, 0x84, 0x33, - 0x01, 0xe4, 0x0b, 0x64, 0x1e, 0x40, 0x04, 0x12, 0x6a, 0x9b, 0x8f, 0x06, 0x20, 0xe4, 0x34, 0x37, - 0x78, 0x03, 0x75, 0xd4, 0x57, 0x24, 0xd4, 0x03, 0xb3, 0xa1, 0x37, 0x4a, 0x05, 0x5e, 0x47, 0xed, - 0xac, 0x34, 0x66, 0x53, 0x6f, 0xe5, 0x12, 0x5e, 0x45, 0x97, 0x1e, 0xf2, 0xd4, 0x03, 0xb3, 0xd5, - 0x35, 0x7a, 0xcb, 0x6e, 0x26, 0x90, 0x07, 0x68, 0xbd, 0x82, 0x7a, 0x3c, 0x62, 0xde, 0x3c, 0x64, - 0x0b, 0x2d, 0xa7, 0x30, 0x0c, 0x45, 0xc8, 0x59, 0x0e, 0x3c, 0x96, 0x15, 0xae, 0x9f, 0x8e, 0xdc, - 0x01, 0xd3, 0xb8, 0xcb, 0x6e, 0x2e, 0x91, 0x18, 0xad, 0x5d, 0x40, 0x10, 0x83, 0x48, 0x62, 0x13, - 0x2d, 0xc5, 0x20, 0x04, 0x0d, 0x0a, 0x8c, 0x42, 0xc4, 0x7b, 0xa8, 0x93, 0x82, 0xe0, 0x83, 0xd4, - 0x03, 0x61, 0x36, 0xba, 0xcd, 0xde, 0xca, 0xee, 0x86, 0x5d, 0xbd, 0x5c, 0x6e, 0xbe, 0x7b, 0x00, - 0x92, 0x86, 0x91, 0x70, 0x4b, 0x73, 0xf2, 0x00, 0x59, 0xd5, 0x34, 0xf2, 0x28, 0x3a, 0xa1, 0x5e, - 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0x82, 0xe7, 0xdf, 0x29, 0xed, 0x3e, 0x1e, 0x12, 0x3e, 0x82, 0x10, 0xb4, 0x28, 0x8e, 0x89, + 0x69, 0xf4, 0x8c, 0x7e, 0xd7, 0xd5, 0x6b, 0xb4, 0x06, 0x5e, 0xa8, 0xd8, 0xb9, 0x44, 0x24, 0x8c, + 0x0a, 0x82, 0xbe, 0x02, 0xe6, 0x01, 0x89, 0x88, 0x24, 0xb5, 0xcd, 0x47, 0x43, 0x22, 0xe4, 0x34, + 0x37, 0x70, 0x03, 0x74, 0xd5, 0x57, 0x24, 0xd8, 0x23, 0x66, 0x43, 0x6f, 0x94, 0x0a, 0xb8, 0x0e, + 0xda, 0x59, 0x69, 0xcc, 0xa6, 0xde, 0xca, 0x25, 0xb8, 0x0a, 0x96, 0x1e, 0x32, 0xee, 0x11, 0xb3, + 0xd5, 0x33, 0xfa, 0x1d, 0x37, 0x13, 0x50, 0x0a, 0xd6, 0x2b, 0xa8, 0xc7, 0x23, 0xea, 0xcd, 0x43, + 0xb6, 0x40, 0x87, 0x93, 0x34, 0x14, 0x21, 0xa3, 0x39, 0xf0, 0x58, 0x56, 0xb8, 0x3e, 0x1f, 0xb9, + 0x43, 0xaa, 0x71, 0x3b, 0x6e, 0x2e, 0x29, 0xdc, 0x84, 0x0f, 0xe9, 0x18, 0x57, 0x0b, 0x28, 0x06, + 0x6b, 0x17, 0x70, 0xc5, 0x30, 0x92, 0xd0, 0x04, 0xcb, 0x31, 0x11, 0x02, 0x07, 0x05, 0x72, 0x21, + 0xc2, 0x3d, 0xd0, 0xe5, 0x44, 0xb0, 0x21, 0xf7, 0x88, 0x30, 0x1b, 0xbd, 0x66, 0x7f, 0x65, 0x77, + 0xc3, 0xae, 0x5e, 0x39, 0x37, 0xdf, 0x3d, 0x20, 0x12, 0x87, 0x91, 0x70, 0x4b, 0x73, 0x94, 0x02, + 0xab, 0x9a, 0x5c, 0x16, 0x45, 0x27, 0xd8, 0x1b, 0xcc, 0x0b, 0x75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 0xc7, 0xf9, 0xa6, 0xf1, 0xf7, 0xf9, + 0xa6, 0xf1, 0x99, 0x3d, 0xef, 0xd7, 0xf5, 0xe2, 0x7f, 0xf9, 0x49, 0x5b, 0xff, 0xa6, 0xbe, 0xf6, + 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x69, 0xad, 0xd8, 0xee, 0xb4, 0x0b, 0x00, 0x00, } diff --git a/server/application/application.proto b/server/application/application.proto index 643b59961c063..16619b293e52e 100644 --- a/server/application/application.proto +++ b/server/application/application.proto @@ -32,6 +32,7 @@ message ApplicationSyncRequest { string name = 1; string revision = 2; bool dryRun = 3; + bool prune = 4; } // ApplicationSyncResult is a result of a sync requeswt @@ -44,6 +45,7 @@ message ApplicationRollbackRequest { string name = 1; int64 id = 2 [(gogoproto.customname) = "ID"]; bool dryRun = 3; + bool prune = 4; } message ResourceDetails { diff --git a/util/kube/kube.go b/util/kube/kube.go index ef9dd4fbd0e6b..17a1f7ebfb8f4 100644 --- a/util/kube/kube.go +++ b/util/kube/kube.go @@ -439,6 +439,27 @@ func deleteFile(path string) { _ = os.Remove(path) } +// DeleteResource deletes resource +func DeleteResource(config *rest.Config, obj *unstructured.Unstructured, namespace string) error { + dynClientPool := dynamic.NewDynamicClientPool(config) + disco, err := discovery.NewDiscoveryClientForConfig(config) + if err != nil { + return err + } + gvk := obj.GroupVersionKind() + dclient, err := dynClientPool.ClientForGroupVersionKind(gvk) + if err != nil { + return err + } + apiResource, err := ServerResourceForGroupVersionKind(disco, gvk) + if err != nil { + return err + } + reIf := dclient.Resource(apiResource, namespace) + propagationPolicy := metav1.DeletePropagationForeground + return reIf.Delete(obj.GetName(), &metav1.DeleteOptions{PropagationPolicy: &propagationPolicy}) +} + // ApplyResource performs an apply of a unstructured resource func ApplyResource(config *rest.Config, obj *unstructured.Unstructured, namespace string) (*unstructured.Unstructured, error) { log.Infof("Applying resource %s/%s in cluster: %s, namespace: %s", obj.GetKind(), obj.GetName(), config.Host, namespace)