Skip to content

Commit 0995fec

Browse files
committed
Fix flattenClusterTemplateRevisions func to avoid crash
1 parent f04b2ca commit 0995fec

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

rancher2/structure_cluster_template.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,24 @@ func flattenClusterTemplateRevisions(input []managementClient.ClusterTemplateRev
123123
}
124124
}
125125
}
126-
sortedInput := make([]managementClient.ClusterTemplateRevision, len(input))
126+
inputLen := len(input)
127+
pLen := len(p)
128+
sortedInput := make([]managementClient.ClusterTemplateRevision, inputLen)
127129
newCTR := []managementClient.ClusterTemplateRevision{}
128130
lastIndex := 0
129131
for i := range sortedInput {
130132
if v, ok := pIndexID[input[i].ID]; ok {
133+
if v > i && pLen > inputLen {
134+
v = v - (v - i)
135+
}
131136
sortedInput[v] = input[i]
132137
lastIndex++
133138
continue
134139
}
135140
if v, ok := pIndexName[input[i].Name]; ok {
141+
if v > i && pLen > inputLen {
142+
v = v - (v - i)
143+
}
136144
sortedInput[v] = input[i]
137145
lastIndex++
138146
continue

0 commit comments

Comments
 (0)