-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from gerald1248/add_route_conflict
identify route conflicts
- Loading branch information
Showing
13 changed files
with
105 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type ItemRouteConflict struct { | ||
name, description, kind string | ||
} | ||
|
||
func (irc *ItemRouteConflict) Name() string { | ||
return irc.name | ||
} | ||
|
||
func (irc *ItemRouteConflict) Description() string { | ||
return irc.description | ||
} | ||
|
||
func (irc *ItemRouteConflict) Kind() string { | ||
return irc.kind | ||
} | ||
|
||
func (irc *ItemRouteConflict) Lint(config *Config, params LinterParams) (ResultMap, error) { | ||
resultRouteConflict := make(ResultMap) | ||
|
||
//populate map with key spec.host and value metadata.name | ||
//only one route (metadata.name) should resolve to a given FQDN stored in spec.host | ||
routeMap := make(map[string]string) | ||
|
||
var key, value string | ||
for _, item := range config.Items { | ||
if item.Kind != irc.Kind() { | ||
continue | ||
} | ||
|
||
if item.Metadata != nil && item.Spec != nil { | ||
//skip if host or targetPort field not present | ||
if item.Spec.Host == "" || item.Spec.Port == nil || item.Spec.Port.TargetPort == 0 { | ||
continue | ||
} | ||
|
||
key = fmt.Sprintf("%s:%d", item.Spec.Host, item.Spec.Port.TargetPort) | ||
value = item.Metadata.Name | ||
|
||
if len(routeMap[key]) > 0 && routeMap[key] != value { | ||
problem := fmt.Sprintf("'%s' and '%s' both name route to '%s'", routeMap[key], value, key) | ||
resultRouteConflict[problem] = append(resultRouteConflict[problem], ContainerSpec{"", "", ""}) | ||
} else { | ||
routeMap[key] = value | ||
} | ||
} | ||
} | ||
return resultRouteConflict, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters