retain pod fields when update with objectwatcher
Signed-off-by: changzhen <changzhen5@huawei.com>
This commit is contained in:
parent
e3dd8cfaa6
commit
0c07ddf469
|
@ -15,6 +15,8 @@ For reference: https://github.com/kubernetes-sigs/kubefed/blob/master/pkg/contro
|
||||||
const (
|
const (
|
||||||
// ServiceKind indicates the target resource is a service
|
// ServiceKind indicates the target resource is a service
|
||||||
ServiceKind = "Service"
|
ServiceKind = "Service"
|
||||||
|
// PodKind indicates the target resource is a pod
|
||||||
|
PodKind = "Pod"
|
||||||
// ServiceAccountKind indicates the target resource is a serviceaccount
|
// ServiceAccountKind indicates the target resource is a serviceaccount
|
||||||
ServiceAccountKind = "ServiceAccount"
|
ServiceAccountKind = "ServiceAccount"
|
||||||
// SecretsField indicates the 'secrets' field of a service account
|
// SecretsField indicates the 'secrets' field of a service account
|
||||||
|
@ -34,6 +36,9 @@ func RetainClusterFields(desiredObj, clusterObj *unstructured.Unstructured) erro
|
||||||
desiredObj.SetFinalizers(clusterObj.GetFinalizers())
|
desiredObj.SetFinalizers(clusterObj.GetFinalizers())
|
||||||
desiredObj.SetAnnotations(clusterObj.GetAnnotations())
|
desiredObj.SetAnnotations(clusterObj.GetAnnotations())
|
||||||
|
|
||||||
|
if targetKind == PodKind {
|
||||||
|
return retainPodFields(desiredObj, clusterObj)
|
||||||
|
}
|
||||||
if targetKind == ServiceKind {
|
if targetKind == ServiceKind {
|
||||||
return retainServiceFields(desiredObj, clusterObj)
|
return retainServiceFields(desiredObj, clusterObj)
|
||||||
}
|
}
|
||||||
|
@ -43,6 +48,20 @@ func RetainClusterFields(desiredObj, clusterObj *unstructured.Unstructured) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func retainPodFields(desiredObj, clusterObj *unstructured.Unstructured) error {
|
||||||
|
nodeName, ok, err := unstructured.NestedString(clusterObj.Object, "spec", "nodeName")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error retrieving nodeName from cluster pod: %w", err)
|
||||||
|
}
|
||||||
|
if ok && nodeName != "" {
|
||||||
|
err := unstructured.SetNestedField(desiredObj.Object, nodeName, "spec", "nodeName")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error setting nodeName for pod: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func retainServiceFields(desiredObj, clusterObj *unstructured.Unstructured) error {
|
func retainServiceFields(desiredObj, clusterObj *unstructured.Unstructured) error {
|
||||||
// healthCheckNodePort is allocated by APIServer and unchangeable, so it should be retained while updating
|
// healthCheckNodePort is allocated by APIServer and unchangeable, so it should be retained while updating
|
||||||
healthCheckNodePort, ok, err := unstructured.NestedInt64(clusterObj.Object, "spec", "healthCheckNodePort")
|
healthCheckNodePort, ok, err := unstructured.NestedInt64(clusterObj.Object, "spec", "healthCheckNodePort")
|
||||||
|
|
Loading…
Reference in New Issue