@@ -91,35 +91,82 @@ func (c ImageRegistryConditions) String() string {
91
91
92
92
func removeImageRegistry (te TestEnv ) {
93
93
te .Logf ("uninstalling the image registry..." )
94
+
95
+ operatorDeployment , err := te .Client ().Deployments (OperatorDeploymentNamespace ).Get (
96
+ context .Background (), OperatorDeploymentName , metav1.GetOptions {},
97
+ )
98
+ if err != nil {
99
+ te .Fatalf ("unable to get the operator deployment: %s" , err )
100
+ }
101
+
102
+ if ! isDeploymentRolledOut (operatorDeployment ) {
103
+ te .Errorf ("unexepected state: the operator is not rolled out before removing the image registry" )
104
+ }
105
+
106
+ if operatorDeployment .Spec .Replicas != nil && * operatorDeployment .Spec .Replicas == 0 {
107
+ config , err := te .Client ().Configs ().Get (
108
+ context .Background (), defaults .ImageRegistryResourceName , metav1.GetOptions {},
109
+ )
110
+ if errors .IsNotFound (err ) {
111
+ return
112
+ } else if err != nil {
113
+ te .Fatalf ("unable to get the image registry config: %s" , err )
114
+ }
115
+ conds := GetImageRegistryConditions (config )
116
+ if ! conds .Removed .IsTrue () {
117
+ te .Fatalf ("unable to uninstall the image registry: the operator is shutted down, but the image registry is not removed: %s" , config .Spec .ManagementState , conds )
118
+ }
119
+ return
120
+ }
121
+
122
+ err = wait .PollImmediate (2 * time .Second , 30 * time .Second , func () (stop bool , err error ) {
123
+ cr , err := te .Client ().Configs ().Get (
124
+ context .Background (), defaults .ImageRegistryResourceName , metav1.GetOptions {},
125
+ )
126
+ if err != nil {
127
+ te .Logf ("the image registry config is not found: %s" , err )
128
+ return false , nil
129
+ }
130
+ if cr .DeletionTimestamp != nil {
131
+ te .Logf ("the image registry config is being deleted: %s" , cr .DeletionTimestamp )
132
+ return false , nil
133
+ }
134
+ return true , nil
135
+ })
136
+ if err != nil {
137
+ te .Fatalf ("failed to wait until the operator creates the config object: %s" , err )
138
+ }
139
+
94
140
if _ , err := te .Client ().Configs ().Patch (
95
141
context .Background (),
96
142
defaults .ImageRegistryResourceName ,
97
143
types .MergePatchType ,
98
144
[]byte (`{"spec": {"managementState": "Removed"}}` ),
99
145
metav1.PatchOptions {},
100
146
); err != nil {
101
- if errors .IsNotFound (err ) {
102
- // That's not exactly what we are asked for. And few seconds later
103
- // the operator may bootstrap it. However, if the operator is
104
- // disabled, it means the registry is not installed and we're
105
- // already in the desired state.
106
- return
107
- }
108
147
te .Fatalf ("unable to uninstall the image registry: %s" , err )
109
148
}
110
149
111
150
var cr * imageregistryapiv1.Config
112
- err : = wait .Poll (5 * time .Second , AsyncOperationTimeout , func () (stop bool , err error ) {
151
+ err = wait .Poll (5 * time .Second , AsyncOperationTimeout , func () (stop bool , err error ) {
113
152
cr , err = te .Client ().Configs ().Get (
114
153
context .Background (), defaults .ImageRegistryResourceName , metav1.GetOptions {},
115
154
)
116
155
if errors .IsNotFound (err ) {
156
+ te .Logf ("waiting for the registry to be removed: the config object does not exist?!" )
117
157
cr = nil
118
158
return true , nil
119
159
} else if err != nil {
160
+ te .Logf ("waiting for the registry to be removed: %s" , err )
120
161
return false , err
121
162
}
122
163
164
+ if cr .Spec .ManagementState != "Removed" {
165
+ DumpYAML (te , "unexpected management state in the config object" , cr )
166
+ DumpOperatorLogs (te )
167
+ te .Fatalf ("unexpected management state: got %s, want Removed" , cr .Spec .ManagementState )
168
+ }
169
+
123
170
conds := GetImageRegistryConditions (cr )
124
171
te .Logf ("waiting for the registry to be removed: %s" , conds )
125
172
return conds .Progressing .IsFalse () && conds .Removed .IsTrue (), nil
0 commit comments