Apply commit label on resources created/updated when '--commitlabel' flag is passed (#2279)

This commit is contained in:
Pradeep Lakshmi Narasimha
2022-01-11 12:31:59 +05:30
committed by GitHub
parent b27043518f
commit 89f80c6f25
17 changed files with 274 additions and 47 deletions
+33 -9
View File
@@ -67,7 +67,7 @@ func (opts *ApplySubCommand) do(input cli.Input) error {
func (opts *ApplySubCommand) run(input cli.Input) error {
specDir := util.GetSpecDir(input)
specIgnore := util.GetSpecIgnore(input)
applyCommitLabel := input.Bool(flagkey.SpecApplyCommitLabel)
deleteResources := input.Bool(flagkey.SpecDelete)
watchResources := input.Bool(flagkey.SpecWatch)
waitForBuild := input.Bool(flagkey.SpecWait)
@@ -112,7 +112,7 @@ func (opts *ApplySubCommand) run(input cli.Input) error {
for {
// read all specs
fr, err := ReadSpecs(specDir, specIgnore)
fr, err := ReadSpecs(specDir, specIgnore, applyCommitLabel)
if err != nil {
return errors.Wrap(err, "error reading specs")
}
@@ -626,7 +626,7 @@ func applyPackages(fclient client.Interface, fr *FissionResources, delete bool)
keep = true
}
if keep && existingObj.Status.BuildStatus == fv1.BuildStatusSucceeded {
if keep && isObjectMetaEqual(existingObj.ObjectMeta, o.ObjectMeta) && existingObj.Status.BuildStatus == fv1.BuildStatusSucceeded {
// nothing to do on the server
metadataMap[mapKey(&o.ObjectMeta)] = existingObj.ObjectMeta
} else {
@@ -726,7 +726,7 @@ func applyFunctions(fclient client.Interface, fr *FissionResources, delete bool)
existingObj, ok := existent[mapKey(&o.ObjectMeta)]
if ok {
// ok, a resource with the same name exists, is it the same?
if reflect.DeepEqual(existingObj.Spec, o.Spec) {
if isObjectMetaEqual(existingObj.ObjectMeta, o.ObjectMeta) && reflect.DeepEqual(existingObj.Spec, o.Spec) {
// nothing to do on the server
metadataMap[mapKey(&o.ObjectMeta)] = existingObj.ObjectMeta
} else {
@@ -809,7 +809,7 @@ func applyEnvironments(fclient client.Interface, fr *FissionResources, delete bo
existingObj, ok := existent[mapKey(&o.ObjectMeta)]
if ok {
// ok, a resource with the same name exists, is it the same?
if reflect.DeepEqual(existingObj.Spec, o.Spec) {
if isObjectMetaEqual(existingObj.ObjectMeta, o.ObjectMeta) && reflect.DeepEqual(existingObj.Spec, o.Spec) {
// nothing to do on the server
metadataMap[mapKey(&o.ObjectMeta)] = existingObj.ObjectMeta
} else {
@@ -892,7 +892,7 @@ func applyHTTPTriggers(fclient client.Interface, fr *FissionResources, delete bo
existingObj, ok := existent[mapKey(&o.ObjectMeta)]
if ok {
// ok, a resource with the same name exists, is it the same?
if reflect.DeepEqual(existingObj.Spec, o.Spec) {
if isObjectMetaEqual(existingObj.ObjectMeta, o.ObjectMeta) && reflect.DeepEqual(existingObj.Spec, o.Spec) {
// nothing to do on the server
metadataMap[mapKey(&o.ObjectMeta)] = existingObj.ObjectMeta
} else {
@@ -975,7 +975,7 @@ func applyKubernetesWatchTriggers(fclient client.Interface, fr *FissionResources
existingObj, ok := existent[mapKey(&o.ObjectMeta)]
if ok {
// ok, a resource with the same name exists, is it the same?
if reflect.DeepEqual(existingObj.Spec, o.Spec) {
if isObjectMetaEqual(existingObj.ObjectMeta, o.ObjectMeta) && reflect.DeepEqual(existingObj.Spec, o.Spec) {
// nothing to do on the server
metadataMap[mapKey(&o.ObjectMeta)] = existingObj.ObjectMeta
} else {
@@ -1058,7 +1058,7 @@ func applyTimeTriggers(fclient client.Interface, fr *FissionResources, delete bo
existingObj, ok := existent[mapKey(&o.ObjectMeta)]
if ok {
// ok, a resource with the same name exists, is it the same?
if reflect.DeepEqual(existingObj.Spec, o.Spec) {
if isObjectMetaEqual(existingObj.ObjectMeta, o.ObjectMeta) && reflect.DeepEqual(existingObj.Spec, o.Spec) {
// nothing to do on the server
metadataMap[mapKey(&o.ObjectMeta)] = existingObj.ObjectMeta
} else {
@@ -1141,7 +1141,7 @@ func applyMessageQueueTriggers(fclient client.Interface, fr *FissionResources, d
existingObj, ok := existent[mapKey(&o.ObjectMeta)]
if ok {
// ok, a resource with the same name exists, is it the same?
if reflect.DeepEqual(existingObj.Spec, o.Spec) {
if isObjectMetaEqual(existingObj.ObjectMeta, o.ObjectMeta) && reflect.DeepEqual(existingObj.Spec, o.Spec) {
// nothing to do on the server
metadataMap[mapKey(&o.ObjectMeta)] = existingObj.ObjectMeta
} else {
@@ -1184,3 +1184,27 @@ func applyMessageQueueTriggers(fclient client.Interface, fr *FissionResources, d
return metadataMap, &ras, nil
}
func isObjectMetaEqual(existingObj, newObj metav1.ObjectMeta) bool {
if !reflect.DeepEqual(existingObj.Labels, newObj.Labels) {
return false
}
existingAnnotations := make(map[string]string)
newAnnotations := make(map[string]string)
for existingObjKey, existingObjVal := range existingObj.Annotations {
if existingObjKey != FISSION_DEPLOYMENT_NAME_KEY && existingObjKey != FISSION_DEPLOYMENT_UID_KEY {
existingAnnotations[existingObjKey] = existingObjVal
}
}
for newObjKey, newObjVal := range newObj.Annotations {
if newObjKey != FISSION_DEPLOYMENT_NAME_KEY && newObjKey != FISSION_DEPLOYMENT_UID_KEY {
newAnnotations[newObjKey] = newObjVal
}
}
return reflect.DeepEqual(existingAnnotations, newAnnotations)
}