Skip to content

Commit 2a60e29

Browse files
committed
progress on README
1 parent a470f94 commit 2a60e29

3 files changed

Lines changed: 173 additions & 30 deletions

File tree

README.md

Lines changed: 142 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,40 @@
22

33
This application is used in the [cloud-native training catalogue](https://www.cloud-native.com/trainings/). The images can be found in [quay](https://quay.io/repository/kubermatic-labs/training-application?tab=tags).
44

5+
The aim of this application is to be used in the context of trainings for Docker, Kubernetes, Istio, Helm, ...
6+
7+
## Functionality of the application
8+
9+
**Nothing**, besides possibly (depending on the application configuration) showing a cute cat image 🙀.
10+
511
## Available Endpoints
612

7-
| Endpoint | Description |
8-
| ------------ | ------------------------------------------------------------------ |
9-
| `/` | Root endpoint, the output depends on the application configuration |
10-
| `/liveness` | Liveness probe |
11-
| `/readiness` | Readiness probe |
13+
> The application offers the following endpoints on **port 8080**
14+
15+
### `/`
16+
17+
Root endpoint, the output depends on the application configuration.
18+
19+
Eg the response could be delayed for a configurable amount of seconds.
20+
21+
### `/liveness`
22+
23+
Endpoint of the application to signal if the application is in a healthy state.
24+
25+
If everything is fine the application will respond with a 200 status code, if not the application should respond with a 503 status code.
26+
27+
### `/readiness`
28+
29+
Endpoint of the application to signal if the application is ready to receive requests.
30+
31+
If everything is fine the application will respond with a 200 status code, if not the application should respond with a 503 status code.
1232

1333
## Available Commands
1434

35+
> The application offers the following commands **via stdin**
36+
37+
TODO tty in docker and k8s
38+
1539
| Command | Description |
1640
| ------------------- | ------------------------------------------------------------------- |
1741
| `help` | Get info about available commands and endpoints |
@@ -25,3 +49,116 @@ This application is used in the [cloud-native training catalogue](https://www.cl
2549
| `leak cpu` | Leak CPU |
2650
| `request <url>` | Request a URL, e.g., `request https://www.kubermatic.com/` |
2751
| `delay / <seconds>` | Set delay for the root endpoint (`/`) in seconds, e.g., `delay / 5` |
52+
53+
## Configuring the application
54+
55+
### `configFilePath`
56+
57+
- **Description**:
58+
- **Type**:
59+
- **Default Value**:
60+
- **Usage**:
61+
| Path to the config file | string | "./training-application.conf" | | application arg, you can set this via eg `./training-application --configFilePath my.conf` |
62+
63+
### `alive`
64+
65+
- **Description**:
66+
- **Type**:
67+
- **Default Value**:
68+
- **Usage**:
69+
70+
| Flag to indicate the applications liveness | bool | true | | configurable via the commands `set alive` and `set dead` |
71+
72+
### `ready`
73+
74+
- **Description**:
75+
- **Type**:
76+
- **Default Value**:
77+
- **Usage**:
78+
79+
| Flag to indicate the applications readiness | bool | false | | true after `startUpDelaySeconds` , false on graceful shutdown; configurable via the commands `set ready` and `set unready` |
80+
81+
### `name`
82+
83+
- **Description**:
84+
- **Type**:
85+
- **Default Value**:
86+
- **Usage**:
87+
88+
| The name of the application | string | "not set" | | via config file or via the environment variable `APP_NAME` |
89+
90+
### `version`
91+
92+
- **Description**:
93+
- **Type**:
94+
- **Default Value**:
95+
- **Usage**:
96+
97+
| The version of the application | string | "not set" | | via config file or via the environment variable `APP_VERSION` |
98+
99+
### `message`
100+
101+
- **Description**:
102+
- **Type**:
103+
- **Default Value**:
104+
- **Usage**:
105+
106+
| A message to be shown on the root endpoint | string | "not set" | | via config file or via the environment variable `APP_MESSAGE` |
107+
108+
### `color`
109+
110+
- **Description**:
111+
- **Type**:
112+
- **Default Value**:
113+
- **Usage**:
114+
115+
| The background color of the root endpoint | string | "not set" | | via config file or via the environment variable `APP_COLOR` |
116+
117+
### `rootDelaySeconds`
118+
119+
- **Description**:
120+
- **Type**:
121+
- **Default Value**:
122+
- **Usage**:
123+
124+
| For delaying requests to the root endpoint | int | 0 | | via config file or via the environment variable `APP_ROOT_DELAY_SECONDS` |
125+
126+
### `startUpDelaySeconds`
127+
128+
- **Description**:
129+
- **Type**:
130+
- **Default Value**:
131+
- **Usage**:
132+
133+
|Time the application will take to start | int | 0 | | via config file or via the environment variable `APP_START_UP_DELAY_SECONDS` |
134+
135+
### `tearDownDelaySeconds`
136+
137+
- **Description**:
138+
- **Type**:
139+
- **Default Value**:
140+
- **Usage**:
141+
142+
| Time the application will take to gracefully shut down | int | 0 | | via config file or via the environment variable `APP_TEAR_DOWN_DELAY_SECONDS` |
143+
144+
### `logToFileOnly`
145+
146+
- **Description**:
147+
- **Type**:
148+
- **Default Value**:
149+
- **Usage**:
150+
151+
| Log **only** to the file `training-application.log`, if set to true no logging to stdout will happen | bool | false | | via config file |
152+
153+
### `catMode`
154+
155+
- **Description**:
156+
- **Type**:
157+
- **Default Value**:
158+
- **Usage**:
159+
160+
| Flag to get cute cat images in the rood endpoint | bool | false | | via config file |
161+
162+
## Running the application
163+
164+
## Building the application

src/config.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ func (appConfig *appConfig) initAppConfig(isReady bool) {
8181
appConfig.applicationVersion = getAppConfigStringValue(fileConfig, "version", "APP_VERSION", "not set")
8282
appConfig.applicationMessage = getAppConfigStringValue(fileConfig, "message", "APP_MESSAGE", "not set")
8383
appConfig.color = getAppConfigStringValue(fileConfig, "color", "APP_COLOR", "not set")
84-
appConfig.logToFileOnly = getAppConfigBoolValue(fileConfig, "logToFileOnly", "APP_LOG_TO_FILE_ONLY", false)
84+
appConfig.logToFileOnly = getAppConfigBoolValue(fileConfig, "logToFileOnly", "", false)
8585
appConfig.rootDelaySeconds = getAppConfigIntValue(fileConfig, "rootDelaySeconds", "APP_ROOT_DELAY_SECONDS", 0)
8686
appConfig.startUpDelaySeconds = getAppConfigIntValue(fileConfig, "startUpDelaySeconds", "APP_START_UP_DELAY_SECONDS", 0)
8787
appConfig.tearDownDelaySeconds = getAppConfigIntValue(fileConfig, "tearDownDelaySeconds", "APP_TEAR_DOWN_DELAY_SECONDS", 0)
88-
appConfig.nodeName = getAppConfigStringValue(fileConfig, "nodeName", "NODE_NAME", "")
89-
appConfig.containerName = getAppConfigStringValue(fileConfig, "containerName", "CONTAINER_NAME", "")
90-
appConfig.podNamespace = getAppConfigStringValue(fileConfig, "podNamespace", "POD_NAMESPACE", "")
91-
appConfig.podName = getAppConfigStringValue(fileConfig, "podName", "POD_NAME", "")
92-
appConfig.podIP = getAppConfigStringValue(fileConfig, "podIP", "POD_IP", "")
93-
catMode := getAppConfigBoolValue(fileConfig, "catMode", "APP_CAT_MODE", false)
88+
appConfig.nodeName = getAppConfigStringValue(nil, "", "NODE_NAME", "")
89+
appConfig.containerName = getAppConfigStringValue(nil, "", "CONTAINER_NAME", "")
90+
appConfig.podNamespace = getAppConfigStringValue(nil, "", "POD_NAMESPACE", "")
91+
appConfig.podName = getAppConfigStringValue(nil, "", "POD_NAME", "")
92+
appConfig.podIP = getAppConfigStringValue(nil, "", "POD_IP", "")
93+
catMode := getAppConfigBoolValue(fileConfig, "catMode", "", false)
9494
if catMode {
9595
appConfig.catImageUrl, err = getCat()
9696
if err != nil {
@@ -100,9 +100,11 @@ func (appConfig *appConfig) initAppConfig(isReady bool) {
100100
}
101101

102102
func getAppConfigStringValue(fileConfig *properties.Properties, fileConfigProperty, envVarName, defaultValue string) string {
103-
envVarValue, envVarExists := os.LookupEnv(envVarName)
104-
if envVarExists {
105-
return envVarValue
103+
if envVarName != "" {
104+
envVarValue, envVarExists := os.LookupEnv(envVarName)
105+
if envVarExists {
106+
return envVarValue
107+
}
106108
}
107109
if fileConfig == nil {
108110
return defaultValue
@@ -111,14 +113,16 @@ func getAppConfigStringValue(fileConfig *properties.Properties, fileConfigProper
111113
}
112114

113115
func getAppConfigBoolValue(fileConfig *properties.Properties, fileConfigProperty, envVarName string, defaultValue bool) bool {
114-
envVarValue, envVarExists := os.LookupEnv(envVarName)
115-
if envVarExists {
116-
value, err := strconv.ParseBool(envVarValue)
117-
if err != nil {
118-
log.Errorf("could not convert envirnment variable named '%s' with value '%s' to bool:", envVarName, envVarValue)
119-
return defaultValue
116+
if envVarName != "" {
117+
envVarValue, envVarExists := os.LookupEnv(envVarName)
118+
if envVarExists {
119+
value, err := strconv.ParseBool(envVarValue)
120+
if err != nil {
121+
log.Errorf("could not convert envirnment variable named '%s' with value '%s' to bool:", envVarName, envVarValue)
122+
return defaultValue
123+
}
124+
return value
120125
}
121-
return value
122126
}
123127
if fileConfig == nil {
124128
return defaultValue
@@ -133,14 +137,16 @@ func getAppConfigBoolValue(fileConfig *properties.Properties, fileConfigProperty
133137
}
134138

135139
func getAppConfigIntValue(fileConfig *properties.Properties, fileConfigProperty, envVarName string, defaultValue int) int {
136-
envVarValue, envVarExists := os.LookupEnv(envVarName)
137-
if envVarExists {
138-
value, err := strconv.Atoi(envVarValue)
139-
if err != nil {
140-
log.Errorf("could not convert envirnment variable named '%s' with value '%s' to int:", envVarName, envVarValue)
141-
return defaultValue
140+
if envVarName != "" {
141+
envVarValue, envVarExists := os.LookupEnv(envVarName)
142+
if envVarExists {
143+
value, err := strconv.Atoi(envVarValue)
144+
if err != nil {
145+
log.Errorf("could not convert envirnment variable named '%s' with value '%s' to int:", envVarName, envVarValue)
146+
return defaultValue
147+
}
148+
return value
142149
}
143-
return value
144150
}
145151
if fileConfig == nil {
146152
return defaultValue

src/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func main() {
6060

6161
func getConfigFilePath() string {
6262
args := os.Args[1:]
63-
if len(args) == 2 && args[0] == "configFilePath" {
63+
if len(args) == 2 && args[0] == "--configFilePath" {
6464
return args[1]
6565
}
6666
log.Info("Config File Path not set, defaulting to './training-application.conf'")

0 commit comments

Comments
 (0)