Skip to content

Commit

Permalink
Fix for flickering application status (#4843)
Browse files Browse the repository at this point in the history
* External API for the validator

* Update deployment args and services for the validator

* Add proper port to the deployment

* Update dep files and goimports

* Fix dep version misalignment

* Fix formatting

* Update image versions

* Remove deprecated labels
  • Loading branch information
janmedrek authored and adamwalach committed Jul 11, 2019
1 parent 1c9ffc5 commit 10dffb0
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 15 deletions.
3 changes: 2 additions & 1 deletion components/application-connectivity-validator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ The Application Connectivity Validator validates client certificate subjects.
It proxies the requests to the Event Service and the Application Registry.

A single instance of the component is deployed for an Application and uses these parameters:
- **proxyPort** - The port on which the reverse proxy is exposed. The default port is `8080`.
- **proxyPort** - The port on which the reverse proxy is exposed. The default port is `8081`.
- **externalAPIPort** - The port on which the external API is exposed. The default port is `8080`.
- **tenant** - The tenant of the Application for which the proxy is deployed. Omitted if empty.
- **group** - The group of the Application for which the proxy is deployed. Omitted if empty.
- **eventServicePathPrefix** - Path prefix for which requests will be forwarded to the Event Service. The default value is `/v1/events`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package main
import (
"fmt"
"net/http"
"sync"

"github.com/kyma-project/kyma/components/application-connectivity-validator/internal/externalapi"

"github.com/kyma-project/kyma/components/application-connectivity-validator/internal/validationproxy"
log "github.com/sirupsen/logrus"
Expand All @@ -27,10 +30,26 @@ func main() {
options.appRegistryPathPrefix,
options.appRegistryHost)

server := http.Server{
proxyServer := http.Server{
Handler: validationproxy.NewHandler(proxyHandler),
Addr: fmt.Sprintf(":%d", options.proxyPort),
}

log.Error(server.ListenAndServe())
externalServer := http.Server{
Handler: externalapi.NewHandler(),
Addr: fmt.Sprintf(":%d", options.externalAPIPort),
}

wg := &sync.WaitGroup{}
wg.Add(1)

go func() {
log.Error(proxyServer.ListenAndServe())
}()

go func() {
log.Error(externalServer.ListenAndServe())
}()

wg.Wait()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type options struct {
proxyPort int
externalAPIPort int
tenant string
group string
eventServicePathPrefix string
Expand All @@ -16,7 +17,8 @@ type options struct {
}

func parseArgs() *options {
proxyPort := flag.Int("proxyPort", 8080, "Proxy port.")
proxyPort := flag.Int("proxyPort", 8081, "Proxy port.")
externalAPIPort := flag.Int("externalAPIPort", 8080, "External API port.")
tenant := flag.String("tenant", "", "Name of the application tenant")
group := flag.String("group", "", "Name of the application group")
eventServicePathPrefix := flag.String("eventServicePathPrefix", "/v1/events", "Prefix of paths that will be directed to the Event Service")
Expand All @@ -27,9 +29,10 @@ func parseArgs() *options {
flag.Parse()

return &options{
proxyPort: *proxyPort,
tenant: *tenant,
group: *group,
proxyPort: *proxyPort,
externalAPIPort: *externalAPIPort,
tenant: *tenant,
group: *group,
eventServicePathPrefix: *eventServicePathPrefix,
eventServiceHost: *eventServiceHost,
appRegistryPathPrefix: *appRegistryPathPrefix,
Expand All @@ -38,10 +41,10 @@ func parseArgs() *options {
}

func (o *options) String() string {
return fmt.Sprintf("--proxyPort=%d --tenant=%s --group=%s "+
return fmt.Sprintf("--proxyPort=%d --externalAPIPort=%d --tenant=%s --group=%s "+
"--eventServicePathPrefix=%s --eventServiceHost=%s "+
"--appRegistryPathPrefix=%s --appRegistryHost=%s",
o.proxyPort, o.tenant, o.group,
o.proxyPort, o.externalAPIPort, o.tenant, o.group,
o.eventServicePathPrefix, o.eventServiceHost,
o.appRegistryPathPrefix, o.appRegistryHost)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package externalapi

import (
"net/http"

"github.com/gorilla/mux"
)

func NewHandler() http.Handler {

router := mux.NewRouter()

router.Path("/v1/health").Handler(NewHealthCheckHandler())

return router
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package externalapi

import (
"net/http"
)

// NewHealthCheckHandler creates handler for performing health check
func NewHealthCheckHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package externalapi

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestHealthCheckHandler_HandleRequest(t *testing.T) {
t.Run("should always respond with 200 status code", func(t *testing.T) {
// given
req, err := http.NewRequest(http.MethodGet, "/v1/health", nil)
require.NoError(t, err)
rr := httptest.NewRecorder()

handler := NewHealthCheckHandler()

// when
handler.ServeHTTP(rr, req)

// then
assert.Equal(t, http.StatusOK, rr.Code)
})
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
apiVersion: v1
kind: Service
metadata:
annotations:
"auth.istio.io/{{ .Values.service.externalapi.port }}": NONE
name: {{ .Release.Name }}-application-gateway-external-api
labels:
application: {{ .Release.Name }}
Expand All @@ -22,8 +20,6 @@ spec:
apiVersion: v1
kind: Service
metadata:
annotations:
"auth.istio.io/{{ .Values.eventService.service.externalapi.port }}": NONE
name: {{ .Release.Name }}-event-service-external-api
labels:
application: {{ .Release.Name }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,30 @@ spec:
args:
- "/applicationconnectivityvalidator"
- "--proxyPort={{ .Values.applicationConnectivityValidator.args.proxyPort }}"
- "--externalAPIPort={{ .Values.applicationConnectivityValidator.args.externalAPIPort }}"
- "--tenant={{ .Values.global.tenant }}"
- "--group={{ .Values.global.group }}"
- "--eventServicePathPrefix=/{{ .Release.Name }}/v1/events"
- "--eventServiceHost={{ .Release.Name }}-event-service-external-api:{{ .Values.eventService.service.externalapi.port }}"
- "--appRegistryPathPrefix=/{{ .Release.Name }}/v1/metadata"
- "--appRegistryHost={{ .Values.applicationConnectivityValidator.args.appRegistryHost }}"
readinessProbe:
httpGet:
path: /v1/health
port: {{ .Values.applicationConnectivityValidator.args.externalAPIPort }}
initialDelaySeconds: 5
periodSeconds: 5
livenessProbe:
httpGet:
path: /v1/health
port: {{ .Values.applicationConnectivityValidator.args.externalAPIPort }}
initialDelaySeconds: 10
periodSeconds: 10
ports:
- containerPort: {{ .Values.applicationConnectivityValidator.args.proxyPort }}
name: http-proxy
- containerPort: {{ .Values.applicationConnectivityValidator.args.externalAPIPort }}
name: http-api-port
---
apiVersion: v1
kind: Service
Expand All @@ -49,6 +64,9 @@ metadata:
spec:
type: ClusterIP
ports:
- port: {{ .Values.applicationConnectivityValidator.args.externalAPIPort }}
protocol: TCP
name: http-api-port
- port: {{ .Values.applicationConnectivityValidator.args.proxyPort }}
protocol: TCP
name: http-proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ service:
externalapi:
port: *externalAPIPort


applicationConnectivityValidator:
image:
pullPolicy: IfNotPresent
args:
proxyPort: 8081
appRegistryHost: application-registry-external-api:8081

externalAPIPort: 8080

istio:
gateway:
Expand Down

0 comments on commit 10dffb0

Please sign in to comment.