@@ -126,6 +126,55 @@ var _ = g.Describe("[sig-api-machinery][Feature:ClusterResourceQuota]", func() {
126
126
configmap := & corev1.ConfigMap {}
127
127
configmap .GenerateName = "test"
128
128
if _ , err := clusterAdminKubeClient .CoreV1 ().ConfigMaps (firstProjectName ).Create (context .Background (), configmap , metav1.CreateOptions {}); err != nil {
129
+ // Istio sometimes create an additional configmap in each namespace, so account for it
130
+ // and retry.
131
+ //
132
+ // Note that the tests that install Istio run in parallel with this test, so we cannot
133
+ // assume that it has or has not created the configmap when we create the quota. Thus
134
+ // we must check here whether the reason we got an error was because this configmap
135
+ // put us over the quota.
136
+ //
137
+ // TODO: Remove the following const and if/else block when we bump to OSSM 3.0.1, which
138
+ // ships a version of Istio that has been patched not to create these configmaps.
139
+ const istioConfigmapName = "istio-ca-root-cert"
140
+ if _ , err := clusterAdminKubeClient .CoreV1 ().ConfigMaps (firstProjectName ).Get (context .Background (), istioConfigmapName , metav1.GetOptions {}); err != nil {
141
+ if ! apierrors .IsNotFound (err ) {
142
+ // Use t.Error here so as to fall through to the t.Fatal below.
143
+ t .Errorf ("unexpected error: %v" , err )
144
+ }
145
+ // The Istio configmap doesn't exist, and therefore The Create must have failed
146
+ // for some other reason; fall through to the t.Fatal for the outer err.
147
+ } else {
148
+ // As the Istio configmap exists in this project, assume that it exists in all
149
+ // projects, and adjust the clusterquota accordingly.
150
+ namespaceInitialCMCount ++
151
+ adjustedMandatoryCMQuantity := resource .NewQuantity (int64 (namespaceInitialCMCount )* 2 , resource .DecimalSI )
152
+ if quota , err := clusterAdminQuotaClient .QuotaV1 ().ClusterResourceQuotas ().Get (context .Background (), cq .Name , metav1.GetOptions {}); err != nil {
153
+ t .Fatalf ("unexpected error: %v" , err )
154
+ } else {
155
+ cq = quota
156
+ }
157
+ q := cq .Spec .Quota .Hard [corev1 .ResourceConfigMaps ]
158
+ q .Sub (* mandatoryCMQuantity )
159
+ q .Add (* adjustedMandatoryCMQuantity )
160
+ cq .Spec .Quota .Hard [corev1 .ResourceConfigMaps ] = q
161
+ if _ , err := clusterAdminQuotaClient .QuotaV1 ().ClusterResourceQuotas ().Update (context .Background (), cq , metav1.UpdateOptions {}); err != nil {
162
+ t .Fatalf ("unexpected error: %v" , err )
163
+ }
164
+ if err := waitForQuotaStatus (clusterAdminQuotaClient , cq .Name , func (quota * quotav1.ClusterResourceQuota ) error {
165
+ if ! equality .Semantic .DeepEqual (quota .Spec .Quota .Hard , quota .Status .Total .Hard ) {
166
+ return fmt .Errorf ("%#v != %#v" , quota .Spec .Quota .Hard , quota .Status .Total .Hard )
167
+ }
168
+ return nil
169
+ }); err != nil {
170
+ t .Fatalf ("unexpected error: %v" , err )
171
+ }
172
+
173
+ // Retry creating the configmap with the quota adjusted for the Istio configmap.
174
+ if _ , err := clusterAdminKubeClient .CoreV1 ().ConfigMaps (firstProjectName ).Create (context .Background (), configmap , metav1.CreateOptions {}); err != nil {
175
+ t .Fatalf ("unexpected error: %v" , err )
176
+ }
177
+ }
129
178
t .Fatalf ("unexpected error: %v" , err )
130
179
}
131
180
if err := waitForQuotaStatus (clusterAdminQuotaClient , cq .Name , func (quota * quotav1.ClusterResourceQuota ) error {
0 commit comments