mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-17 05:24:26 +00:00
Do not assume a port name is a string when clearing node ports (#10132)
Run the E2E test on kind / setup-test-matrix (push) Failing after 2s
Scorecard supply-chain security / Scorecard analysis (push) Skipped
e2e-test-kind.yaml / extract (push) Failing after 6s
Run the E2E test on kind / get-go-version (push) Failing after 7s
Run the E2E test on kind / build (push) Skipped
Run the E2E test on kind / run-e2e-test (push) Skipped
push.yml / extract (push) Failing after 6s
Main CI / get-go-version (push) Failing after 7s
Main CI / Build (push) Skipped
Run the E2E test on kind / setup-test-matrix (push) Failing after 2s
Scorecard supply-chain security / Scorecard analysis (push) Skipped
e2e-test-kind.yaml / extract (push) Failing after 6s
Run the E2E test on kind / get-go-version (push) Failing after 7s
Run the E2E test on kind / build (push) Skipped
Run the E2E test on kind / run-e2e-test (push) Skipped
push.yml / extract (push) Failing after 6s
Main CI / get-go-version (push) Failing after 7s
Main CI / Build (push) Skipped
* Do not assume a port name is a string when clearing node ports deleteNodePorts reads the last-applied-configuration annotation, which is free-form JSON controlled by whoever produced the backup, and cast p["name"] to string without checking. A port whose name is a number crashed the restore of that Service with an interface conversion panic. Every sibling in the same loop already uses the comma-ok form. Signed-off-by: Arpit Jain <arpitjain099@gmail.com> * Add changelog file Signed-off-by: Arpit Jain <arpitjain099@gmail.com> * Convert name to string by Sprint. Signed-off-by: Xun Jiang <xun.jiang@broadcom.com> --------- Signed-off-by: Arpit Jain <arpitjain099@gmail.com> Signed-off-by: Xun Jiang <xun.jiang@broadcom.com> Co-authored-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Fix a panic when a port name in the last-applied-configuration annotation is not a string
|
||||
@@ -194,7 +194,7 @@ func deleteNodePorts(service *corev1api.Service) error {
|
||||
// unnamed port
|
||||
unnamedPortInts.Insert(nodePortInt)
|
||||
} else {
|
||||
explicitNodePorts.Insert(portName.(string))
|
||||
explicitNodePorts.Insert(fmt.Sprint(portName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,6 +674,44 @@ func TestServiceActionExecute(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "If a port name in last-applied-configuration is not a string, it should not crash.",
|
||||
obj: corev1api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "svc-1",
|
||||
Annotations: map[string]string{
|
||||
"kubectl.kubernetes.io/last-applied-configuration": `{"spec":{"ports":[{"nodePort":30001,"name":123}]}}`,
|
||||
},
|
||||
},
|
||||
Spec: corev1api.ServiceSpec{
|
||||
Type: corev1api.ServiceTypeNodePort,
|
||||
Ports: []corev1api.ServicePort{
|
||||
{
|
||||
Name: "http",
|
||||
NodePort: 30001,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
restore: builder.ForRestore(api.DefaultNamespace, "").PreserveNodePorts(false).Result(),
|
||||
expectedRes: corev1api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "svc-1",
|
||||
Annotations: map[string]string{
|
||||
"kubectl.kubernetes.io/last-applied-configuration": `{"spec":{"ports":[{"nodePort":30001,"name":123}]}}`,
|
||||
},
|
||||
},
|
||||
Spec: corev1api.ServiceSpec{
|
||||
Type: corev1api.ServiceTypeNodePort,
|
||||
Ports: []corev1api.ServicePort{
|
||||
{
|
||||
Name: "http",
|
||||
NodePort: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
Reference in New Issue
Block a user