Files
open-cluster-management/test/integration/util/work.go
Wei Liu 628d0d90ec
Some checks failed
Scorecard supply-chain security / Scorecard analysis (push) Failing after 2m22s
Post / coverage (push) Failing after 38m27s
Post / images (amd64) (push) Failing after 8m48s
Post / images (arm64) (push) Failing after 8m9s
Post / image manifest (push) Has been skipped
Post / trigger clusteradm e2e (push) Has been skipped
Close stale issues and PRs / stale (push) Successful in 1m3s
cloudevents services integration test (#1086)
Signed-off-by: Wei Liu <liuweixa@redhat.com>
2025-07-23 13:55:55 +00:00

45 lines
901 B
Go

package util
import (
"encoding/json"
"fmt"
jsonpatch "github.com/evanphx/json-patch"
workapiv1 "open-cluster-management.io/api/work/v1"
)
const (
KubeDriver = "kube"
MQTTDriver = "mqtt"
GRPCDriver = "grpc"
)
func NewWorkPatch(old, new *workapiv1.ManifestWork) ([]byte, error) {
oldData, err := json.Marshal(old)
if err != nil {
return nil, err
}
newData, err := json.Marshal(new)
if err != nil {
return nil, err
}
patchBytes, err := jsonpatch.CreateMergePatch(oldData, newData)
if err != nil {
return nil, err
}
return patchBytes, nil
}
func AppliedManifestWorkName(sourceDriver, hubHash string, work *workapiv1.ManifestWork) string {
if sourceDriver != KubeDriver {
// if the source is not kube, the uid will be used as the manifestwork name on the agent side
return fmt.Sprintf("%s-%s", hubHash, work.UID)
}
return fmt.Sprintf("%s-%s", hubHash, work.Name)
}