mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-20 08:04:52 +00:00
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
Signed-off-by: Wei Liu <liuweixa@redhat.com>
45 lines
901 B
Go
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)
|
|
}
|