-
Notifications
You must be signed in to change notification settings - Fork 101
Prioritise API with api write=on #1315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d11d7a5
99d0db9
14977b6
5552230
ed28bf1
6a55e69
66cc63b
aeb6c68
a5e6be4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,15 @@ type ( | |
current *crossplane.Directive, apiType string) []*model.APIDetails | ||
) | ||
|
||
type createAPIDetailsParams struct { | ||
locationDirectiveName string | ||
address string | ||
path string | ||
caCertLocation string | ||
isSSL bool | ||
writeEnabled bool | ||
} | ||
|
||
func NewNginxConfigParser(agentConfig *config.Config) *NginxConfigParser { | ||
return &NginxConfigParser{ | ||
agentConfig: agentConfig, | ||
|
@@ -251,6 +260,8 @@ func (ncp *NginxConfigParser) createNginxConfigContext( | |
nginxConfigContext.PlusAPIs = append(nginxConfigContext.PlusAPIs, plusAPIs...) | ||
} | ||
|
||
nginxConfigContext.PlusAPIs = ncp.sortPlusAPIs(nginxConfigContext.PlusAPIs) | ||
|
||
if len(napSyslogServersFound) > 0 { | ||
var napSyslogServer []string | ||
for server := range napSyslogServersFound { | ||
|
@@ -699,11 +710,22 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective( | |
addresses := ncp.parseAddressFromServerDirective(parent) | ||
path := ncp.parsePathFromLocationDirective(current) | ||
|
||
writeEnabled := ncp.isWriteEnabled(locChild) | ||
|
||
if locChild.Directive == locationDirectiveName { | ||
for _, address := range addresses { | ||
params := createAPIDetailsParams{ | ||
locationDirectiveName: locationDirectiveName, | ||
address: address, | ||
path: path, | ||
caCertLocation: caCertLocation, | ||
isSSL: isSSL, | ||
writeEnabled: writeEnabled, | ||
} | ||
|
||
details = append( | ||
details, | ||
ncp.createAPIDetails(locationDirectiveName, address, path, caCertLocation, isSSL), | ||
ncp.createAPIDetails(params), | ||
) | ||
} | ||
} | ||
|
@@ -713,28 +735,30 @@ func (ncp *NginxConfigParser) apiDetailsFromLocationDirective( | |
} | ||
|
||
func (ncp *NginxConfigParser) createAPIDetails( | ||
locationDirectiveName, address, path, caCertLocation string, isSSL bool, | ||
params createAPIDetailsParams, | ||
) (details *model.APIDetails) { | ||
if strings.HasPrefix(address, "unix:") { | ||
if strings.HasPrefix(params.address, "unix:") { | ||
format := unixStubStatusFormat | ||
|
||
if locationDirectiveName == plusAPIDirective { | ||
if params.locationDirectiveName == plusAPIDirective { | ||
format = unixPlusAPIFormat | ||
} | ||
|
||
details = &model.APIDetails{ | ||
URL: fmt.Sprintf(format, path), | ||
Listen: address, | ||
Location: path, | ||
Ca: caCertLocation, | ||
URL: fmt.Sprintf(format, params.path), | ||
Listen: params.address, | ||
Location: params.path, | ||
Ca: params.caCertLocation, | ||
WriteEnabled: params.writeEnabled, | ||
} | ||
} else { | ||
details = &model.APIDetails{ | ||
URL: fmt.Sprintf("%s://%s%s", map[bool]string{true: "https", false: "http"}[isSSL], | ||
address, path), | ||
Listen: address, | ||
Location: path, | ||
Ca: caCertLocation, | ||
URL: fmt.Sprintf("%s://%s%s", map[bool]string{true: "https", false: "http"}[params.isSSL], | ||
params.address, params.path), | ||
Listen: params.address, | ||
Location: params.path, | ||
Ca: params.caCertLocation, | ||
WriteEnabled: params.writeEnabled, | ||
} | ||
} | ||
|
||
|
@@ -888,3 +912,33 @@ func (ncp *NginxConfigParser) isDuplicateFile(nginxConfigContextFiles []*mpi.Fil | |
|
||
return false | ||
} | ||
|
||
func (ncp *NginxConfigParser) isWriteEnabled(locChild *crossplane.Directive) bool { | ||
if locChild.Directive != plusAPIDirective { | ||
return false | ||
} | ||
|
||
for _, arg := range locChild.Args { | ||
if strings.EqualFold(arg, "write=on") { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (ncp *NginxConfigParser) sortPlusAPIs(apis []*model.APIDetails) []*model.APIDetails { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment or update the naming to explain that this is trying to prioritise and find apis with write enabled? |
||
slices.SortFunc(apis, func(a, b *model.APIDetails) int { | ||
if a.WriteEnabled && !b.WriteEnabled { | ||
return -1 | ||
} | ||
|
||
if b.WriteEnabled && !a.WriteEnabled { | ||
return 1 | ||
} | ||
|
||
return 0 | ||
}) | ||
|
||
return apis | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does a change need to happen to the MPI ? Do the management planes care about the write status ? Could the change instead only be made to the
APIDetails struct
thats internal to the Agent?