Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func main() {
var verifiedUnidling bool
var verifiedSecret string

var defaultHTTPResponseCode int

flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
flag.BoolVar(&secureMetrics, "metrics-secure", true,
Expand Down Expand Up @@ -108,11 +110,13 @@ func main() {
flag.StringVar(&verifiedSecret, "verify-secret", "super-secret-string",
"The secret to use for verifying unidling requests.")
flag.IntVar(&unidlerHTTPPort, "unidler-port", 5000, "Port for the unidler service to listen on.")
flag.IntVar(&defaultHTTPResponseCode, "default-http-response-code", 404, "Default HTTP response code.")
flag.Parse()

selectorsFile = variables.GetEnv("SELECTORS_YAML_FILE", selectorsFile)
verifiedUnidling = variables.GetEnvBool("VERIFIED_UNIDLING", verifiedUnidling)
verifiedSecret = variables.GetEnv("VERIFY_SECRET", verifiedSecret)
defaultHTTPResponseCode = variables.GetEnvInt("DEFAULT_HTTP_RESPONSE_CODE", defaultHTTPResponseCode)

dryRun = variables.GetEnvBool("DRY_RUN", dryRun)

Expand Down Expand Up @@ -198,17 +202,18 @@ func main() {
allowedIPs, _ := unidler.ReadSliceFromFile("/lists/allowedips")
blockedIPs, _ := unidler.ReadSliceFromFile("/lists/blockedips")
u := &unidler.Unidler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("aergia-controller").WithName("Unidler"),
RefreshInterval: refreshInterval,
Debug: debug,
AllowedUserAgents: allowedAgents,
BlockedUserAgents: blockedAgents,
AllowedIPs: allowedIPs,
BlockedIPs: blockedIPs,
UnidlerHTTPPort: unidlerHTTPPort,
VerifiedUnidling: verifiedUnidling,
VerifiedSecret: verifiedSecret,
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("aergia-controller").WithName("Unidler"),
RefreshInterval: refreshInterval,
Debug: debug,
AllowedUserAgents: allowedAgents,
BlockedUserAgents: blockedAgents,
AllowedIPs: allowedIPs,
BlockedIPs: blockedIPs,
UnidlerHTTPPort: unidlerHTTPPort,
VerifiedUnidling: verifiedUnidling,
VerifiedSecret: verifiedSecret,
DefaultHTTPResponseCode: defaultHTTPResponseCode,
}

prometheusClient, err := prometheusapi.NewClient(prometheusapi.Config{
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/unidler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (h *Unidler) ingressHandler(path string) func(http.ResponseWriter, *http.Re
errCode := r.Header.Get(CodeHeader)
code, err := strconv.Atoi(errCode)
if err != nil {
code = 404
code = h.DefaultHTTPResponseCode
}
w.WriteHeader(code)
ns := r.Header.Get(Namespace)
Expand Down
25 changes: 13 additions & 12 deletions internal/handlers/unidler/unidler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ const (

// Unidler is the client structure for http handlers.
type Unidler struct {
Client ctrlClient.Client
Log logr.Logger
RefreshInterval int
UnidlerHTTPPort int
Debug bool
VerifiedUnidling bool
VerifiedSecret string
Locks sync.Map
AllowedUserAgents []string
BlockedUserAgents []string
AllowedIPs []string
BlockedIPs []string
Client ctrlClient.Client
Log logr.Logger
RefreshInterval int
UnidlerHTTPPort int
Debug bool
VerifiedUnidling bool
VerifiedSecret string
Locks sync.Map
AllowedUserAgents []string
BlockedUserAgents []string
AllowedIPs []string
BlockedIPs []string
DefaultHTTPResponseCode int
}

type pageData struct {
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ var _ = ginkgo.Describe("controller", ginkgo.Ordered, func() {
fmt.Printf("metrics: %s", string(output))
err = utils.CheckStringContainsStrings(string(output), metricLabels)
gomega.ExpectWithOffset(2, err).NotTo(gomega.HaveOccurred())

// verify that default HTTP response code is 404
ginkgo.By("validating default HTTP response code")
runCmd = fmt.Sprintf(`curl -s -I http://non-existing-domain.%s.nip.io/`, kindIP)
output, _ = utils.RunCommonsCommand(namespace, runCmd)
fmt.Printf("curl: %s", string(output))
err = utils.CheckStringContainsStrings(string(output), []string{"404 Not Found"})
gomega.ExpectWithOffset(2, err).NotTo(gomega.HaveOccurred())
// End tests
})
})
Expand Down