feat: Extended api/wss retrieval to check configuration before going to the ingress
And save results to configuration when going to the ingress was needed.
@@ -6,6 +6,7 @@ import (
"github.com/epinio/epinio/deployments"
"github.com/epinio/epinio/helpers/kubernetes"
+ "github.com/epinio/epinio/internal/cli/config"
"github.com/pkg/errors"
)
@@ -24,10 +25,32 @@ type EpinioAPIClient struct {
var epinioClientMemo *EpinioAPIClient
func GetEpinioAPIClient(ctx context.Context) (*EpinioAPIClient, error) {
+ // Check for information cached in memory, and return if such is found
if epinioClientMemo != nil {
return epinioClientMemo, nil
}
+ // Check for information cached in the peinio configuration,
+ // and return if such is found. Cache into memory as well.
+ configConfig, err := config.Load()
+ if err != nil {
+ return nil, err
+ }
+
+ if configConfig.API != "" && configConfig.WSS != "" {
+ epinioClient := &EpinioAPIClient{
+ URL: configConfig.API,
+ WsURL: configConfig.WSS,
+ }
+
+ epinioClientMemo = epinioClient
+
+ return epinioClient, nil
+ }
+
+ // Not cached at all. Query and return the cluster
+ // ingress. Cache to configuration, and memory.
+
cluster, err := kubernetes.GetCluster(ctx)
if err != nil {
return nil, err
@@ -38,6 +61,14 @@ func GetEpinioAPIClient(ctx context.Context) (*EpinioAPIClient, error) {
return nil, errors.Wrap(err, "failed to resolve epinio api host")
}
+ configConfig.API = epinioURL
+ configConfig.WSS = epinioWsURL
+
+ err = configConfig.Save()
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to save configuration")
+ }
+
epinioClient := &EpinioAPIClient{
URL: epinioURL,
WsURL: epinioWsURL,
