Skip to content

Commit

Permalink
[TASK-1008] fix: create destination bug (#1345)
Browse files Browse the repository at this point in the history
add a secret to destination owner only if it exists
  • Loading branch information
alonkeyval authored Jul 10, 2024
1 parent d41aa29 commit 666d9ee
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions frontend/endpoints/destinations.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ func CreateNewDestination(c *gin.Context, odigosns string) {
return
}

err = addDestinationOwnerReferenceToSecret(c, odigosns, dest)
if err != nil {
returnError(c, err)
return
if dest.Spec.SecretRef != nil {
err = addDestinationOwnerReferenceToSecret(c, odigosns, dest)
if err != nil {
returnError(c, err)
return
}
}

resp := k8sDestinationToEndpointFormat(*dest, secretFields)
Expand Down Expand Up @@ -604,21 +606,21 @@ func createDestinationSecret(ctx context.Context, destType common.DestinationTyp

func addDestinationOwnerReferenceToSecret(ctx context.Context, odigosns string, dest *v1alpha1.Destination) error {
destOwnerRef := metav1.OwnerReference{
APIVersion: "odigos.io/v1alpha1",
Kind: "Destination",
Name: dest.Name,
UID: dest.UID,
APIVersion: "odigos.io/v1alpha1",
Kind: "Destination",
Name: dest.Name,
UID: dest.UID,
}

secretPatch := []struct{
Op string `json:"op"`
Path string `json:"path"`
secretPatch := []struct {
Op string `json:"op"`
Path string `json:"path"`
Value []metav1.OwnerReference `json:"value"`
} {{
Op: "add",
Path: "/metadata/ownerReferences",
}{{
Op: "add",
Path: "/metadata/ownerReferences",
Value: []metav1.OwnerReference{destOwnerRef},
},
},
}

secretPatchBytes, err := json.Marshal(secretPatch)
Expand Down

0 comments on commit 666d9ee

Please sign in to comment.