Skip to content

Commit

Permalink
Updating the declare api URI for CM
Browse files Browse the repository at this point in the history
  • Loading branch information
vklohiya committed Mar 7, 2024
1 parent 60ca50f commit 3effed7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 deletions.
30 changes: 11 additions & 19 deletions pkg/controller/as3PostManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
)

func (postMgr *AS3PostManager) createAS3Declaration(tenantDeclMap map[string]as3Tenant, userAgent, targetAddress string) as3Declaration {
func (postMgr *AS3PostManager) createAS3Declaration(tenantDeclMap map[string]as3Tenant, userAgent string) as3Declaration {
var as3Config map[string]interface{}
var adc map[string]interface{}
var baseAS3ConfigTemplate string
Expand All @@ -19,10 +19,6 @@ func (postMgr *AS3PostManager) createAS3Declaration(tenantDeclMap map[string]as3
postMgr.AS3VersionInfo.as3Release)
_ = json.Unmarshal([]byte(baseAS3ConfigTemplate), &as3Config)
adc = as3Config["declaration"].(map[string]interface{})
// Set the target address for ADC
adc["target"] = as3Target{
"address": targetAddress,
}
} else {
baseAS3ConfigTemplate = baseAS3Config2
_ = json.Unmarshal([]byte(baseAS3ConfigTemplate), &as3Config)
Expand Down Expand Up @@ -100,7 +96,7 @@ func processDataGroupForAS3(rsMap ResourceMap, sharedApp as3Application) {
dgMap.Records = append(dgMap.Records, as3Record{Key: record.Name, Value: record.Data})
}
// sort above create dgMap records.
sort.Slice(dgMap.Records, func(i, j int) bool { return (dgMap.Records[i].Key < dgMap.Records[j].Key) })
sort.Slice(dgMap.Records, func(i, j int) bool { return dgMap.Records[i].Key < dgMap.Records[j].Key })
sharedApp[dg.Name] = dgMap
} else {
for _, record := range dg.Records {
Expand Down Expand Up @@ -137,7 +133,7 @@ func processResourcesForAS3(rsMap ResourceMap, sharedApp as3Application, shareNo
createServiceDecl(cfg, sharedApp, tenant)
case TransportServer:
//Create AS3 Service for transport virtual server
createTransportServiceDecl(cfg, sharedApp, tenant, documentAPI)
createTransportServiceDecl(cfg, sharedApp, tenant)
}
}
}
Expand Down Expand Up @@ -510,7 +506,7 @@ func createRuleCondition(rl *Rule, rulesData *as3Rule, port int) {
if c.Host {
condition.Name = "host"
var values []string
// For ports other then 80 and 443, attaching port number to host.
// For ports other than 80 and 443, attaching port number to host.
// Ex. example.com:8080
if port != 80 && port != 443 {
for i := range c.Values {
Expand Down Expand Up @@ -682,7 +678,7 @@ func processProfilesForAS3(rsMap ResourceMap, sharedApp as3Application) {
}

func processTLSProfilesForAS3(virtual *Virtual, svc *as3Service, profileName string) {
// lets discard BIGIP profile creation when there exists a custom profile.
// let's discard BIGIP profile creation when there exists a custom profile.
as3ClientSuffix := "_tls_client"
as3ServerSuffix := "_tls_server"
var clientProfiles []as3MultiTypeParam
Expand Down Expand Up @@ -767,7 +763,7 @@ func processCustomProfilesForAS3(rsMap ResourceMap, sharedApp as3Application, as
if as3Version < 3.44 {
return
}
for svcName, _ := range svcNameMap {
for svcName := range svcNameMap {
if _, ok := sharedApp[svcName].(*as3Service); ok {
tlsServerName := fmt.Sprintf("%s_tls_server", svcName)
tlsServer, ok := sharedApp[tlsServerName].(*as3TLSServer)
Expand Down Expand Up @@ -892,7 +888,7 @@ func createMonitorDecl(cfg *ResourceConfig, sharedApp as3Application) {
}

// Create AS3 transport Service for CRD
func createTransportServiceDecl(cfg *ResourceConfig, sharedApp as3Application, tenant string, documentAPI bool) {
func createTransportServiceDecl(cfg *ResourceConfig, sharedApp as3Application, tenant string) {
svc := &as3Service{}
if cfg.Virtual.Mode == "standard" {
if cfg.Virtual.IpProtocol == "udp" {
Expand Down Expand Up @@ -991,13 +987,9 @@ func createTransportServiceDecl(cfg *ResourceConfig, sharedApp as3Application, t
as3SharedApplication,
ps[len(ps)-1],
)
if !documentAPI {
var poolPointer as3ResourcePointer
poolPointer.Use = poolValue
svc.Pool = &poolPointer
} else {
svc.Pool = poolValue
}

svc.Pool = poolValue

processCommonDecl(cfg, svc)
sharedApp[cfg.Virtual.Name] = svc
}
Expand Down Expand Up @@ -1087,7 +1079,7 @@ func (req *RequestHandler) createAS3Config(rsConfig ResourceConfigRequest, pm *P
}
}
}
as3cfg.data = string(pm.AS3PostManager.createAS3Declaration(as3cfg.incomingTenantDeclMap, req.userAgent, rsConfig.bigIpKey.BigIpAddress))
as3cfg.data = string(pm.AS3PostManager.createAS3Declaration(as3cfg.incomingTenantDeclMap, req.userAgent))
return as3cfg
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/controller/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,10 @@ const AbDeploymentDgName = "ab_deployment_dg"

const BigIPLabel = ""

const CM_DECLARE_API = "/api/v1/spaces/default/appsvcs/documents/"
const CmDocumentApi = "/api/v1/spaces/default/appsvcs/documents/"

const CmDeclareApi = "/api/v1/spaces/default/appsvcs/declare/"

const CmDeclareTaskApi = "/api/v1/spaces/default/appsvcs/task/"

const CmDeclareInfoApi = "/api/v1/spaces/default/appsvcs/info"
20 changes: 10 additions & 10 deletions pkg/controller/postManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,28 @@ func (postMgr *PostManager) setupBIGIPRESTClient() {
}
}

func (postMgr *PostManager) getAS3APIURL(tenants []string) string {
func (postMgr *PostManager) getAS3APIURL(bigipAddress string) string {
// TODO: Add tenant filtering when support is added in Central Manger AS3
//apiURL := postMgr.tokenManager.ServerURL + "/mgmt/shared/appsvcs/declare/" + strings.Join(tenants, ",")
//apiURL := postMgr.tokenManager.ServerURL + CmDeclareApi + strings.Join(tenants, ",")
var apiURL string
if !postMgr.AS3Config.DocumentAPI {
apiURL = postMgr.tokenManager.ServerURL + "/mgmt/shared/appsvcs/declare/"
apiURL = postMgr.tokenManager.ServerURL + CmDeclareApi
} else {
apiURL = postMgr.tokenManager.ServerURL + CM_DECLARE_API
apiURL = postMgr.tokenManager.ServerURL + CmDocumentApi + "?target_address=" + bigipAddress
}
return apiURL
}

func (postMgr *PostManager) getAS3TaskIdURL(taskId string) string {
var apiURL string
if !postMgr.AS3Config.DocumentAPI {
apiURL = postMgr.tokenManager.ServerURL + "/mgmt/shared/appsvcs/task/" + taskId
apiURL = postMgr.tokenManager.ServerURL + CmDeclareTaskApi + taskId
} else {
ids := strings.Split(taskId, "/")
if len(ids) != 2 {
return ""
}
apiURL = postMgr.tokenManager.ServerURL + CM_DECLARE_API + ids[0] + "/deployments/" + ids[1]
apiURL = postMgr.tokenManager.ServerURL + CmDocumentApi + ids[0] + "/deployments/" + ids[1]
}
return apiURL
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (postMgr *PostManager) postConfig(cfg *as3Config) {
}
}
}
cfg.as3APIURL = postMgr.getAS3APIURL(tenants)
cfg.as3APIURL = postMgr.getAS3APIURL(cfg.targetAddress)
req, err := http.NewRequest("POST", cfg.as3APIURL, httpReqBody)
if err != nil {
log.Errorf("%v[AS3]%v Creating new HTTP request error: %v ", getRequestPrefix(cfg.id), postMgr.postManagerPrefix, err)
Expand Down Expand Up @@ -252,7 +252,7 @@ func (postMgr *PostManager) postConfigUsingDocumentAPI(cfg *as3Config) {
if len(tenants) == 0 {
tenants = append(tenants, postMgr.defaultPartition)
}
cfg.as3APIURL = postMgr.getAS3APIURL(tenants)
cfg.as3APIURL = postMgr.getAS3APIURL(cfg.targetAddress)
method := "POST"
declarationID := postMgr.tenantDeclarationIDMap[tenants[0]]
if declarationID != "" {
Expand Down Expand Up @@ -714,7 +714,7 @@ func (postMgr *PostManager) GetBigipRegKey() (string, error) {
}

func (postMgr *PostManager) GetAS3DeclarationFromBigIP() (map[string]interface{}, error) {
url := postMgr.getAS3APIURL([]string{})
url := postMgr.getAS3APIURL("")
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Errorf("[AS3]%v Creating new HTTP request error: %v ", postMgr.postManagerPrefix, err)
Expand Down Expand Up @@ -769,7 +769,7 @@ func (postMgr *PostManager) httpReq(request *http.Request) (*http.Response, map[
}

func (postMgr *PostManager) getAS3VersionURL() string {
apiURL := postMgr.tokenManager.ServerURL + "/mgmt/shared/appsvcs/info"
apiURL := postMgr.tokenManager.ServerURL + CmDeclareInfoApi
return apiURL
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/postManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("AS3PostManager Tests", func() {
BeforeEach(func() {
as3Cfg = as3Config{
data: `{"declaration": {"test": {"Shared": {"class": "application"}}}}`,
as3APIURL: mockPM.getAS3APIURL([]string{"test"}),
as3APIURL: mockPM.getAS3APIURL(as3Cfg.targetAddress),
id: 0,
tenantResponseMap: make(map[string]tenantResponse),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/requestHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ var _ = Describe("Backend Tests", func() {

server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/mgmt/shared/appsvcs/info"),
ghttp.VerifyRequest("GET", CmDeclareInfoApi),
ghttp.RespondWithJSONEncoded(statusCode, map1),
))
})
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3975,16 +3975,15 @@ func (ctlr *Controller) processCNIConfig(configCR *cisapiv1.DeployConfig) {
if ctlr.PoolMemberType == NodePort || ctlr.PoolMemberType == NodePortLocal {
ctlr.shareNodes = true
if ctlr.StaticRoutingMode && ctlr.PoolMemberType != Auto {
log.Errorf("static route CNI: %v not supported with nodeport/nodeportlocal mode. Only supported with cluster mode", ctlr.OrchestrationCNI)
os.Exit(1)
log.Warningf("static route CNI: %v not supported with nodeport/nodeportlocal mode. Only supported with cluster mode", ctlr.OrchestrationCNI)
}
} else if ctlr.PoolMemberType == Cluster || ctlr.PoolMemberType == Auto {
if ctlr.StaticRoutingMode {
ctlr.StaticRouteNodeCIDR = configCR.Spec.NetworkConfig.MetaData.NetworkCIDR
} else if ctlr.OrchestrationCNI == FLANNEL || ctlr.OrchestrationCNI == CILIUM ||
ctlr.OrchestrationCNI == OPENSHIFTSDN {
if configCR.Spec.NetworkConfig.MetaData.TunnelName == "" {
log.Errorf("tunnelName is not set in CIS Config CR")
log.Errorf("tunnelName is required for CIS cluster mode with CNI: %v", ctlr.OrchestrationCNI)
os.Exit(1)
}
} else {
Expand Down

0 comments on commit 3effed7

Please sign in to comment.