Skip to content

Commit

Permalink
removal of dynamic env enable flag considering the review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
slahirucd7 committed Jan 24, 2025
1 parent 3895236 commit 5d0614d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 122 deletions.
1 change: 0 additions & 1 deletion adapter/config/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ var defaultConfig = &Config{
OrganizationID: "",
EnvironmentLabels: []string{"Default"},
DynamicEnvironments: dynamicEnvironments{
Enabled: false,
DataPlaneID: "$env{data_plane_id}",
GatewayAccessibilityType: DefaultGatewayAccessibilityType,
},
Expand Down
1 change: 0 additions & 1 deletion adapter/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ type asbDataplaneTopic struct {
}

type dynamicEnvironments struct {
Enabled bool
DataPlaneID string
GatewayAccessibilityType string
}
Expand Down
17 changes: 5 additions & 12 deletions adapter/internal/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,10 @@ func fetchChunkedAPIsOnStartUp(conf *config.Config, apiUUIDList []string, xdsOpt
queryParamMap = common.PopulateQueryParamForOrganizationID(queryParamMap)
// Get API details.
if apiUUIDList == nil {
if conf.ControlPlane.DynamicEnvironments.Enabled {
queryParamMap = common.PopulateQueryParamForDataPlane(queryParamMap)
adapter.GetAPIs(c, nil, nil, sync.RetrieveRuntimeArtifactEndpoint, true, nil, queryParamMap)
} else {
adapter.GetAPIs(c, nil, envs, sync.RuntimeArtifactEndpoint, true, nil, queryParamMap)
}
} else if conf.ControlPlane.DynamicEnvironments.Enabled {
queryParamMap = common.PopulateQueryParamForDataPlane(queryParamMap)
adapter.GetAPIs(c, nil, nil, sync.RetrieveRuntimeArtifactEndpoint, true, nil, queryParamMap)

} else {
queryParamMap = common.PopulateQueryParamForDataPlane(queryParamMap)
adapter.GetAPIs(c, nil, nil, sync.RetrieveRuntimeArtifactEndpoint, true, apiUUIDList, queryParamMap)
}
Expand All @@ -397,11 +394,7 @@ func fetchChunkedAPIsOnStartUp(conf *config.Config, apiUUIDList []string, xdsOpt
i--
logger.LoggerMgw.Errorf("Error occurred while fetching data from control plane: %v", data.Err)
health.SetControlPlaneRestAPIStatus(false)
if conf.ControlPlane.DynamicEnvironments.Enabled {
sync.RetryFetchingAPIs(c, data, sync.RetrieveRuntimeArtifactEndpoint, true, queryParamMap, apiUUIDList)
} else {
sync.RetryFetchingAPIs(c, data, sync.RuntimeArtifactEndpoint, true, queryParamMap, apiUUIDList)
}
sync.RetryFetchingAPIs(c, data, sync.RetrieveRuntimeArtifactEndpoint, true, queryParamMap, apiUUIDList)
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions adapter/internal/api/apis_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,6 @@ func ApplyAPIProjectFromAPIM(
}
loggers.LoggerAPI.Infof("Deploying api %s:%s in Organization %s", apiYaml.Name, apiYaml.Version, apiProject.OrganizationID)

conf, _ := config.ReadConfigs()
currentEnv := conf.ControlPlane.EnvironmentLabels[0] // assumption - adapter has only one environment

if apiEnvs[apiProject.APIYaml.Data.ID][currentEnv].APIConfigs.SandboxEndpointChoreo != "" &&
!conf.ControlPlane.DynamicEnvironments.Enabled {
vhostToEnvsMap[conf.Adapter.SandboxVhost] = []*synchronizer.GatewayLabel{
{
Name: currentEnv,
Vhost: conf.Adapter.SandboxVhost,
DeploymentType: "SANDBOX",
},
}
}

// TODO: (renuka) optimize to update cache only once when all internal memory maps are updated
for vhost, environments := range vhostToEnvsMap {

Expand Down
13 changes: 4 additions & 9 deletions adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,8 @@ func UpdateAPI(vHost string, apiProject mgw.ProjectAPI, deployedEnvironments []*
// When the dynamicEnvironments support is enabled, it will be setting the xds cache under the
// common label(global label for gateway), which is obtained from conf.ControlPlane.EnvironmentLabels and
// it will always be in size 1 for choreo.
if conf.ControlPlane.DynamicEnvironments.Enabled {
routerLabels = conf.ControlPlane.EnvironmentLabels
} else {
routerLabels = environments
}
routerLabels = conf.ControlPlane.EnvironmentLabels

logger.LoggerXds.Infof("Added/Updated the content for Organization : %v under OpenAPI Key : %v", organizationID, apiIdentifier)
logger.LoggerXds.Debugf("Newly added labels for Organization : %v for the OpenAPI Key : %v are %v", organizationID, apiIdentifier, routerLabels)
oldLabels, _ := orgIDOpenAPIEnvoyMap[organizationID][apiIdentifier]
Expand Down Expand Up @@ -702,10 +699,8 @@ func deleteAPI(apiIdentifier string, environments []string, organizationID strin
// common label (which will be set in conf.ControlPlane.EnvironmentLabels), if the deployment of particular
// API is exists in orgIDOpenAPIEnvoyMap
// Note: In this case orgIDOpenAPIEnvoyMap eventually has same label for all the entries (APIs).
if conf.ControlPlane.DynamicEnvironments.Enabled {
if len(existingLabels) == 1 {
toBeDelEnvs = existingLabels
}
if len(existingLabels) == 1 {
toBeDelEnvs = existingLabels
} else {
toBeDelEnvs, toBeKeptEnvs = getEnvironmentsToBeDeleted(existingLabels, environments)
}
Expand Down
18 changes: 5 additions & 13 deletions adapter/internal/ga/api_event_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,17 @@ func handleAPIEventsFromGA(channel chan APIEvent) {
configuredEnvs = append(configuredEnvs, config.DefaultGatewayName)
}
if !event.IsDeployEvent {
if conf.ControlPlane.DynamicEnvironments.Enabled {
xds.DeleteAPIWithAPIMEvent(event.APIUUID, event.OrganizationUUID, []string{event.DeployedEnv}, event.RevisionUUID)
} else {
xds.DeleteAPIWithAPIMEvent(event.APIUUID, event.OrganizationUUID, configuredEnvs, event.RevisionUUID)
}
xds.DeleteAPIWithAPIMEvent(event.APIUUID, event.OrganizationUUID, []string{event.DeployedEnv}, event.RevisionUUID)
// TODO: (VirajSalaka) Temporarily removed.
// for _, env := range configuredEnvs {
// xds.DeleteAPIAndReturnList(event.APIUUID, event.OrganizationUUID, env)
// }
continue
}
if conf.ControlPlane.DynamicEnvironments.Enabled {
go synchronizer.FetchAPIsFromControlPlane(event.APIUUID,
[]string{event.DeployedEnv},
map[string]string{event.DeployedEnv: conf.ControlPlane.DynamicEnvironments.DataPlaneID},
map[string]string{event.DeployedEnv: conf.ControlPlane.DynamicEnvironments.GatewayAccessibilityType})
} else {
go synchronizer.FetchAPIsFromControlPlane(event.APIUUID, configuredEnvs, nil, nil)
}
go synchronizer.FetchAPIsFromControlPlane(event.APIUUID,
[]string{event.DeployedEnv},
map[string]string{event.DeployedEnv: conf.ControlPlane.DynamicEnvironments.DataPlaneID},
map[string]string{event.DeployedEnv: conf.ControlPlane.DynamicEnvironments.GatewayAccessibilityType})

// TODO: (VirajSalaka) temporarily removed.
// for _, env := range configuredEnvs {
Expand Down
33 changes: 10 additions & 23 deletions adapter/internal/ga/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func generateTLSCredentialsForXdsClient() credentials.TransportCredentials {
}

func watchAPIs() {
conf, _ := config.ReadConfigs()
for {
discoveryResponse, err := xdsStream.Recv()
if err == io.EOF {
Expand All @@ -166,11 +165,7 @@ func watchAPIs() {
logger.LoggerGA.Debugf("Discovery response is received : %s, size: %d", discoveryResponse.VersionInfo,
len(discoveryResponse.Resources))
// ToDO: (VajiraPrabuddhaka) remove this check once the dynamic environment changes are fully rolled out
if conf.ControlPlane.DynamicEnvironments.Enabled {
addAPIWithEnvToChannel(discoveryResponse)
} else {
addAPIToChannel(discoveryResponse)
}
addAPIWithEnvToChannel(discoveryResponse)
ack()
}
}
Expand Down Expand Up @@ -207,30 +202,22 @@ func nack(errorMessage string) {

func getAdapterNode() *core.Node {
config, _ := config.ReadConfigs()
if config.ControlPlane.DynamicEnvironments.Enabled {
return &core.Node{
Id: fmt.Sprintf("%s-%s-%s",
config.ControlPlane.DynamicEnvironments.DataPlaneID,
config.ControlPlane.DynamicEnvironments.GatewayAccessibilityType,
config.GlobalAdapter.LocalLabel),
}
}
return &core.Node{
Id: config.GlobalAdapter.LocalLabel,
Id: fmt.Sprintf("%s-%s-%s",
config.ControlPlane.DynamicEnvironments.DataPlaneID,
config.ControlPlane.DynamicEnvironments.GatewayAccessibilityType,
config.GlobalAdapter.LocalLabel),
}
}

// InitGAClient initializes the connection to the global adapter.
func InitGAClient() {
config, _ := config.ReadConfigs()
if config.ControlPlane.DynamicEnvironments.Enabled {
logger.LoggerGA.Infof("Starting the XDS Client connection for %s-%s-%s to Global Adapter.",
config.ControlPlane.DynamicEnvironments.DataPlaneID,
config.ControlPlane.DynamicEnvironments.GatewayAccessibilityType,
config.GlobalAdapter.LocalLabel)
} else {
logger.LoggerGA.Infof("Starting the XDS Client connection to Global Adapter.")
}
logger.LoggerGA.Infof("Starting the XDS Client connection for %s-%s-%s to Global Adapter.",
config.ControlPlane.DynamicEnvironments.DataPlaneID,
config.ControlPlane.DynamicEnvironments.GatewayAccessibilityType,
config.GlobalAdapter.LocalLabel)

go handleAPIEventsFromGA(GAAPIChannel)
conn := initializeAndWatch()
for retryTrueReceived := range connectionFaultChannel {
Expand Down
22 changes: 3 additions & 19 deletions adapter/internal/oasparser/model/mgw_swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,25 +474,9 @@ func (swagger *MgwSwagger) SetEnvLabelProperties(envProps synchronizer.APIEnvPro
var productionUrls []Endpoint
var sandboxUrls []Endpoint

conf, _ := config.ReadConfigs()

if isChoreoSandbox {
if envProps.APIConfigs.SandboxEndpointChoreo != "" && !conf.ControlPlane.DynamicEnvironments.Enabled {
logger.LoggerOasparser.Infof("SandboxEndpointChoreo is found in env properties for %v : %v",
swagger.title, swagger.version)
endpoint, err := getHTTPEndpoint(envProps.APIConfigs.SandboxEndpointChoreo)
if err == nil {
productionUrls = append(productionUrls, *endpoint)
} else {
logger.LoggerOasparser.Errorf("Error encountered when parsing the Choreo sandbox endpoint for %v : %v. %v",
swagger.title, swagger.version, err.Error())
}
}

if len(productionUrls) > 0 {
logger.LoggerOasparser.Infof("Production endpoint is overridden by env property SandboxEndpointChoreo %v : %v", swagger.title, swagger.version)
swagger.productionEndpoints = generateEndpointCluster(prodClustersConfigNamePrefix, productionUrls, LoadBalance)
}
if isChoreoSandbox && len(productionUrls) > 0 {
logger.LoggerOasparser.Infof("Production endpoint is overridden by env property SandboxEndpointChoreo %v : %v", swagger.title, swagger.version)
swagger.productionEndpoints = generateEndpointCluster(prodClustersConfigNamePrefix, productionUrls, LoadBalance)
return
}

Expand Down
41 changes: 12 additions & 29 deletions adapter/internal/synchronizer/apis_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func PushAPIProjects(payload []byte, environments []string, xdsOptions common.Xd

// TODO: (renuka) notify the revision deployment to the control plane once all chunks are deployed.
// This is not fixed as notify the control plane chunk by chunk (even though the chunk is not really applied to the Enforcer and Router) is not a drastic issue.
// This path is only happening when Adapter is restarting and at that time the deployed time is already updated in the control plane.
// This path is only happening when Adapter is restarting and at that time the deployed time is already updated in the control plane.
notifier.SendRevisionUpdate(deploymentList)
logger.LoggerSync.Infof("Successfully deployed %d API/s", len(deploymentList))
// Error nil for successful execution
Expand Down Expand Up @@ -175,38 +175,21 @@ func FetchAPIsFromControlPlane(updatedAPIID string, updatedEnvs []string, envToD
// This has to be error. For debugging purpose info
logger.LoggerSync.Errorf("Error reading configs: %v", errReadConfig)
}
configuredEnvs := conf.ControlPlane.EnvironmentLabels

//finalEnvs contains the actual environments that the adapter should update
var finalEnvs []string

// if the dynamic environment support feature enabled, finalEnvs should be the envs in envToDpMap,
// due to the dynamic environment support feature, finalEnvs should be the envs in envToDpMap,
// whose data plane ID matches with the data Plane ID defined in the gateway configs
if conf.ControlPlane.DynamicEnvironments.Enabled {
for gwEnv, dpID := range envToDpMap {
// following if condition checks whether the environment corresponds to the configured data-plane and
// gateway accessibility type (internal or external).
// it assumes that the envToDpMap and envToGwAccessibilityTypeMap are identical in gateway environments.
if strings.EqualFold(conf.ControlPlane.DynamicEnvironments.DataPlaneID, dpID) &&
strings.EqualFold(conf.ControlPlane.DynamicEnvironments.GatewayAccessibilityType,
envToGwAccessibilityTypeMap[gwEnv]) {
finalEnvs = append(finalEnvs, gwEnv)
}
}
} else {
if len(configuredEnvs) > 0 {
// If the configuration file contains environment list, then check if then check if the
// affected environments are present in the provided configs. If so, add that environment
// to the finalEnvs slice
for _, updatedEnv := range updatedEnvs {
for _, configuredEnv := range configuredEnvs {
if updatedEnv == configuredEnv {
finalEnvs = append(finalEnvs, updatedEnv)
}
}
}
} else {
// If the labels are not configured, publish the APIS to the default environment
finalEnvs = []string{config.DefaultGatewayName}

for gwEnv, dpID := range envToDpMap {
// following if condition checks whether the environment corresponds to the configured data-plane and
// gateway accessibility type (internal or external).
// it assumes that the envToDpMap and envToGwAccessibilityTypeMap are identical in gateway environments.
if strings.EqualFold(conf.ControlPlane.DynamicEnvironments.DataPlaneID, dpID) &&
strings.EqualFold(conf.ControlPlane.DynamicEnvironments.GatewayAccessibilityType,
envToGwAccessibilityTypeMap[gwEnv]) {
finalEnvs = append(finalEnvs, gwEnv)
}
}

Expand Down
1 change: 0 additions & 1 deletion resources/conf/config.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ enabled = true
# Configs related to the dynamic environment support
# When enabled, CC will decide which apis to be deployed using the combination of dataPlaneID and gatewayAccessibilityType
[controlPlane.dynamicEnvironments]
enabled = false
dataPlaneID = "$env{data_plane_id}"
gatewayAccessibilityType = "$env{gateway_accessibility_type}"
# Message broker connection URL of the control plane
Expand Down

0 comments on commit 5d0614d

Please sign in to comment.