You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
changes=append(changes, fmt.Sprintf(" %s -> from %v to %v", k, currentVal, desiredVal))
1058
+
// Format the values for better readability
1059
+
currentStr:=formatValue(currentVal)
1060
+
desiredStr:=formatValue(desiredVal)
1061
+
changes=append(changes, fmt.Sprintf(" - %s:\n from: %s\n to: %s",
1062
+
k, currentStr, desiredStr))
1033
1063
}
1034
1064
}
1035
1065
}
1036
1066
1037
1067
iflen(changes) >0 {
1038
-
returncommon.ResultCodeSyncFailed, fmt.Sprintf("one or more objects failed to apply, reason: attempting to change immutable fields:\n%s\nForbidden: updates to statefulset spec for fields other than 'replicas', 'ordinals', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden",
1068
+
// Sort the changes to ensure consistent order
1069
+
sort.Strings(changes)
1070
+
returncommon.ResultCodeSyncFailed, fmt.Sprintf("one or more objects failed to apply, reason: attempting to change immutable fields:\n%s\n\nForbidden: updates to statefulset spec for fields other than 'replicas', 'ordinals', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden",
expectedMessage: `one or more objects failed to apply, reason: attempting to change immutable fields:
2061
+
- serviceName:
2062
+
from: "old-svc"
2063
+
to: "new-svc"
2064
+
2065
+
Forbidden: updates to statefulset spec for fields other than 'replicas', 'ordinals', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden`,
2066
+
},
2067
+
{
2068
+
name: "volumeClaimTemplates change from nil",
2069
+
currentSpec: map[string]interface{}{
2070
+
"serviceName": "test-svc",
2071
+
},
2072
+
desiredSpec: map[string]interface{}{
2073
+
"serviceName": "test-svc",
2074
+
"volumeClaimTemplates": []interface{}{
2075
+
map[string]interface{}{
2076
+
"metadata": map[string]interface{}{
2077
+
"name": "data",
2078
+
},
2079
+
},
2080
+
},
2081
+
},
2082
+
expectedMessage: `one or more objects failed to apply, reason: attempting to change immutable fields:
2083
+
- volumeClaimTemplates:
2084
+
from: <nil>
2085
+
to: templates: [data]
2086
+
2087
+
Forbidden: updates to statefulset spec for fields other than 'replicas', 'ordinals', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden`,
2088
+
},
2089
+
{
2090
+
name: "multiple immutable field changes",
2091
+
currentSpec: map[string]interface{}{
2092
+
"serviceName": "old-svc",
2093
+
"podManagementPolicy": "OrderedReady",
2094
+
},
2095
+
desiredSpec: map[string]interface{}{
2096
+
"serviceName": "new-svc",
2097
+
"podManagementPolicy": "Parallel",
2098
+
},
2099
+
expectedMessage: `one or more objects failed to apply, reason: attempting to change immutable fields:
2100
+
- podManagementPolicy:
2101
+
from: "OrderedReady"
2102
+
to: "Parallel"
2103
+
- serviceName:
2104
+
from: "old-svc"
2105
+
to: "new-svc"
2106
+
2107
+
Forbidden: updates to statefulset spec for fields other than 'replicas', 'ordinals', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden`,
2108
+
},
2109
+
{
2110
+
name: "complex volumeClaimTemplates change",
2111
+
currentSpec: map[string]interface{}{
2112
+
"volumeClaimTemplates": []interface{}{
2113
+
map[string]interface{}{
2114
+
"metadata": map[string]interface{}{
2115
+
"name": "data1",
2116
+
},
2117
+
},
2118
+
},
2119
+
},
2120
+
desiredSpec: map[string]interface{}{
2121
+
"volumeClaimTemplates": []interface{}{
2122
+
map[string]interface{}{
2123
+
"metadata": map[string]interface{}{
2124
+
"name": "data1",
2125
+
},
2126
+
},
2127
+
map[string]interface{}{
2128
+
"metadata": map[string]interface{}{
2129
+
"name": "data2",
2130
+
},
2131
+
},
2132
+
},
2133
+
},
2134
+
expectedMessage: `one or more objects failed to apply, reason: attempting to change immutable fields:
2135
+
- volumeClaimTemplates:
2136
+
from: templates: [data1]
2137
+
to: templates: [data1, data2]
2138
+
2139
+
Forbidden: updates to statefulset spec for fields other than 'replicas', 'ordinals', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden`,
2140
+
},
2141
+
}
2142
+
2143
+
for_, tt:=rangetests {
2144
+
t.Run(tt.name, func(t*testing.T) {
2145
+
current:=&unstructured.Unstructured{
2146
+
Object: map[string]interface{}{
2147
+
"apiVersion": "apps/v1",
2148
+
"kind": "StatefulSet",
2149
+
"metadata": map[string]interface{}{
2150
+
"name": "test-statefulset",
2151
+
"namespace": "default",
2152
+
},
2153
+
"spec": tt.currentSpec,
2154
+
},
2155
+
}
2156
+
2157
+
desired:=&unstructured.Unstructured{
2158
+
Object: map[string]interface{}{
2159
+
"apiVersion": "apps/v1",
2160
+
"kind": "StatefulSet",
2161
+
"metadata": map[string]interface{}{
2162
+
"name": "test-statefulset",
2163
+
"namespace": "default",
2164
+
},
2165
+
"spec": tt.desiredSpec,
2166
+
},
2167
+
}
2168
+
2169
+
task:=&syncTask{
2170
+
liveObj: current,
2171
+
targetObj: desired,
2172
+
}
2173
+
2174
+
sc:=newTestSyncCtx(nil)
2175
+
2176
+
// Mock the resource operations to return immutable field error
2177
+
mockResourceOps:=&kubetest.MockResourceOps{
2178
+
Commands: map[string]kubetest.KubectlOutput{
2179
+
"test-statefulset": {
2180
+
Err: errors.New("Forbidden: updates to statefulset spec for fields other than 'replicas', 'ordinals', 'template', 'updateStrategy', 'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden"),
0 commit comments