|
| 1 | +package openbaocluster |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "fmt" |
| 7 | + |
| 8 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 9 | + "k8s.io/apimachinery/pkg/runtime" |
| 10 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 11 | + |
| 12 | + openbaov1alpha1 "github.com/dc-tec/openbao-operator/api/v1alpha1" |
| 13 | + "github.com/dc-tec/openbao-operator/internal/platform/constants" |
| 14 | + networkingmanager "github.com/dc-tec/openbao-operator/internal/service/networking" |
| 15 | +) |
| 16 | + |
| 17 | +// IngressIntegrationDependencies groups infrastructure readers required to |
| 18 | +// evaluate the operator-owned ingress integration contract. |
| 19 | +type IngressIntegrationDependencies struct { |
| 20 | + Client client.Client |
| 21 | + APIReader client.Reader |
| 22 | + Scheme *runtime.Scheme |
| 23 | + OperatorNamespace string |
| 24 | + Platform string |
| 25 | +} |
| 26 | + |
| 27 | +// IngressIntegrationResult is the controller-facing evaluation result for the |
| 28 | +// operator-managed ingress contract. |
| 29 | +type IngressIntegrationResult struct { |
| 30 | + Status metav1.ConditionStatus |
| 31 | + Reason string |
| 32 | + Message string |
| 33 | +} |
| 34 | + |
| 35 | +// EvaluateIngressIntegration validates the operator-managed ingress |
| 36 | +// prerequisites and controller support for the selected ingress mode. |
| 37 | +func EvaluateIngressIntegration( |
| 38 | + ctx context.Context, |
| 39 | + deps IngressIntegrationDependencies, |
| 40 | + cluster *openbaov1alpha1.OpenBaoCluster, |
| 41 | +) IngressIntegrationResult { |
| 42 | + manager := networkingmanager.NewManagerWithReader( |
| 43 | + deps.Client, |
| 44 | + deps.APIReader, |
| 45 | + deps.Scheme, |
| 46 | + deps.OperatorNamespace, |
| 47 | + deps.Platform, |
| 48 | + ) |
| 49 | + err := manager.ValidateIngressIntegration(ctx, cluster) |
| 50 | + |
| 51 | + switch { |
| 52 | + case err == nil: |
| 53 | + return IngressIntegrationResult{ |
| 54 | + Status: metav1.ConditionTrue, |
| 55 | + Reason: constants.ReasonIngressIntegrationReady, |
| 56 | + Message: "Ingress integration prerequisites are satisfied", |
| 57 | + } |
| 58 | + case errors.Is(err, networkingmanager.ErrIngressClassMissing): |
| 59 | + return IngressIntegrationResult{ |
| 60 | + Status: metav1.ConditionFalse, |
| 61 | + Reason: constants.ReasonIngressClassMissing, |
| 62 | + Message: err.Error(), |
| 63 | + } |
| 64 | + case errors.Is(err, networkingmanager.ErrIngressObjectMissing): |
| 65 | + return IngressIntegrationResult{ |
| 66 | + Status: metav1.ConditionUnknown, |
| 67 | + Reason: constants.ReasonIngressObjectPending, |
| 68 | + Message: err.Error(), |
| 69 | + } |
| 70 | + case errors.Is(err, networkingmanager.ErrIngressLoadBalancerPending): |
| 71 | + return IngressIntegrationResult{ |
| 72 | + Status: metav1.ConditionUnknown, |
| 73 | + Reason: constants.ReasonIngressLoadBalancerPending, |
| 74 | + Message: err.Error(), |
| 75 | + } |
| 76 | + case errors.Is(err, networkingmanager.ErrIngressCapabilitiesUnknown): |
| 77 | + return IngressIntegrationResult{ |
| 78 | + Status: metav1.ConditionUnknown, |
| 79 | + Reason: constants.ReasonIngressCapabilitiesUnknown, |
| 80 | + Message: err.Error(), |
| 81 | + } |
| 82 | + default: |
| 83 | + return IngressIntegrationResult{ |
| 84 | + Status: metav1.ConditionUnknown, |
| 85 | + Reason: constants.ReasonUnknown, |
| 86 | + Message: fmt.Sprintf("Failed to evaluate ingress integration prerequisites: %v", err), |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments