@@ -17,6 +17,7 @@ limitations under the License.
1717package main
1818
1919import (
20+ "context"
2021 "flag"
2122 "fmt"
2223 "net/http"
@@ -28,11 +29,8 @@ import (
2829 // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2930 // to ensure that exec-entrypoint and run can make use of them.
3031 _ "k8s.io/client-go/plugin/pkg/client/auth"
32+ "sigs.k8s.io/controller-runtime/pkg/manager"
3133
32- "github.com/kelseyhightower/envconfig"
33- bmh_v1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
34- hivev1 "github.com/openshift/hive/apis/hive/v1"
35- "github.com/sirupsen/logrus"
3634 corev1 "k8s.io/api/core/v1"
3735 "k8s.io/apimachinery/pkg/labels"
3836 "k8s.io/apimachinery/pkg/runtime"
@@ -46,6 +44,11 @@ import (
4644 metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4745 "sigs.k8s.io/controller-runtime/pkg/webhook"
4846
47+ "github.com/kelseyhightower/envconfig"
48+ bmh_v1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
49+ hivev1 "github.com/openshift/hive/apis/hive/v1"
50+ "github.com/sirupsen/logrus"
51+
4952 "github.com/openshift/image-based-install-operator/api/v1alpha1"
5053 "github.com/openshift/image-based-install-operator/controllers"
5154 "github.com/openshift/image-based-install-operator/internal/credentials"
@@ -191,13 +194,44 @@ func main() {
191194 os .Exit (1 )
192195 }
193196
197+ go EnqueueExistingImageClusterInstall (mgr )
198+
194199 setupLog .Info ("starting manager" )
195200 if err := mgr .Start (ctrl .SetupSignalHandler ()); err != nil {
196201 setupLog .Error (err , "problem running manager" )
197202 os .Exit (1 )
198203 }
199204}
200205
206+ func EnqueueExistingImageClusterInstall (mgr manager.Manager ) {
207+ ctx := context .Background ()
208+
209+ // Wait for cache to sync
210+ setupLog .Info ("Waiting for cache to sync..." )
211+ if synced := mgr .GetCache ().WaitForCacheSync (ctx ); ! synced {
212+ setupLog .Error (fmt .Errorf ("Failed to wait for cache to sync" ), "failed to wait for cache to sync while enqueuing existing ImageClusterInstall" )
213+ os .Exit (1 )
214+ }
215+ setupLog .Info ("Cache successfully started and synced" )
216+
217+ // List existing resources and enqueue those with ClusterInstallCompleted condition false
218+ var icilList v1alpha1.ImageClusterInstallList
219+ if err := mgr .GetClient ().List (ctx , & icilList ); err != nil {
220+ setupLog .Error (err , "Failed to list ImageClusterInstall" )
221+ os .Exit (1 )
222+ }
223+
224+ for _ , ici := range icilList .Items {
225+ if ! controllers .InstallationCompleted (& ici ) {
226+ setupLog .Info ("Enqueuing existing ImageClusterInstall:" , "namespace" , ici .Namespace , "name" , ici .Name )
227+ // Triggers reconciliation
228+ if err := mgr .GetClient ().Status ().Update (ctx , & ici ); err != nil {
229+ setupLog .Info ("Failed to requeue ImageClusterInstall" , "namespace" , ici .Namespace , "name" , ici .Name )
230+ }
231+ }
232+ }
233+ }
234+
201235func serviceURL (opts * controllers.ImageClusterInstallReconcilerOptions ) (string , error ) {
202236 if opts .ServiceName == "" || opts .ServiceNamespace == "" || opts .ServiceScheme == "" {
203237 return "" , fmt .Errorf ("SERVICE_NAME, SERVICE_NAMESPACE, and SERVICE_SCHEME must be set" )
0 commit comments