Skip to content

Commit

Permalink
remove hanging apis in the startup flow
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowleyRajapakse committed Feb 16, 2024
1 parent 2d2aea1 commit 5d2512a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apim-apk-agent/internal/utils/apis_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"strings"

"github.com/wso2/product-apim-tooling/apim-apk-agent/config"
internalk8sClient "github.com/wso2/product-apim-tooling/apim-apk-agent/internal/k8sClient"
logger "github.com/wso2/product-apim-tooling/apim-apk-agent/pkg/loggers"
"github.com/wso2/product-apim-tooling/apim-apk-agent/pkg/logging"
sync "github.com/wso2/product-apim-tooling/apim-apk-agent/pkg/synchronizer"
Expand Down Expand Up @@ -58,6 +59,9 @@ func FetchAPIsOnEvent(conf *config.Config, apiUUID *string, k8sClient client.Cli
// Populate data from config.
envs := conf.ControlPlane.EnvironmentLabels

apiUUIDs := []string{}
startup := false

// Create a channel for the byte slice (response from the APIs from control plane)
c := make(chan sync.SyncAPIResponse)

Expand All @@ -66,6 +70,7 @@ func FetchAPIsOnEvent(conf *config.Config, apiUUID *string, k8sClient client.Cli
GetAPI(c, apiUUID, envs, sync.RuntimeArtifactEndpoint, true)
} else {
GetAPI(c, nil, envs, sync.RuntimeArtifactEndpoint, true)
startup = true
}
data := <-c
logger.LoggerMsg.Info("Receiving data for an API")
Expand Down Expand Up @@ -116,6 +121,9 @@ func FetchAPIsOnEvent(conf *config.Config, apiUUID *string, k8sClient client.Cli
logger.LoggerSync.Errorf("Error while generating APK-Conf: %v", apkErr)
return
}
if startup {
apiUUIDs = append(apiUUIDs, apiUUID)
}
k8ResourceEndpoint := conf.DataPlane.K8ResourceEndpoint
crResponse, err := transformer.GenerateCRs(apkConf, artifact.Swagger, k8ResourceEndpoint)
if err != nil {
Expand All @@ -129,6 +137,11 @@ func FetchAPIsOnEvent(conf *config.Config, apiUUID *string, k8sClient client.Cli
}
}

if startup {
// Undeploy the APIs which are not available in the provided API UUIDs
internalk8sClient.UndeployAPICRs(apiUUIDs, k8sClient)
}

} else if data.ErrorCode == 204 {
logger.LoggerMsg.Infof("No API Artifacts are available in the control plane for the envionments :%s",
strings.Join(envs, ", "))
Expand Down

0 comments on commit 5d2512a

Please sign in to comment.