func()

in operator/controllers/operator/oapserverdynamicconfig_controller.go [69:109]


func (r *OAPServerDynamicConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	_ = log.FromContext(ctx)

	log := runtimelog.FromContext(ctx)
	log.Info("=====================oapserverdynamicconfig reconcile started================================")

	config := operatorv1alpha1.OAPServerDynamicConfig{}
	if err := r.Client.Get(ctx, req.NamespacedName, &config); err != nil {
		return ctrl.Result{}, client.IgnoreNotFound(err)
	}

	oapList := operatorv1alpha1.OAPServerList{}
	opts := []client.ListOption{
		client.InNamespace(req.Namespace),
	}

	if err := r.List(ctx, &oapList, opts...); err != nil && !apierrors.IsNotFound(err) {
		return ctrl.Result{}, fmt.Errorf("failed to list oapserver: %w", err)
	}

	// get the specific version's oapserver
	for i := range oapList.Items {
		if oapList.Items[i].Spec.Version == config.Spec.Version {
			oapServer := oapList.Items[i]
			// Update the dynamic configuration
			err := r.UpdateDynamicConfig(ctx, log, &oapServer, &config)
			if err != nil {
				log.Error(err, "failed to update the dynamic configuration")
				return ctrl.Result{}, err
			}

		}
	}

	if err := r.checkState(ctx, log, &config); err != nil {
		log.Error(err, "failed to update OAPServerDynamicConfig's status")
		return ctrl.Result{}, err
	}

	return ctrl.Result{RequeueAfter: schedDuration}, nil
}