Skip to content

Commit 397294a

Browse files
committed
finish readme, consolidate configuration possibilities
1 parent 2a60e29 commit 397294a

6 files changed

Lines changed: 140 additions & 112 deletions

File tree

README.md

Lines changed: 92 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The aim of this application is to be used in the context of trainings for Docker
1010

1111
## Available Endpoints
1212

13-
> The application offers the following endpoints on **port 8080**
13+
> **_NOTE:_** The application offers the following endpoints on port **8080**
1414
1515
### `/`
1616

@@ -32,9 +32,7 @@ If everything is fine the application will respond with a 200 status code, if no
3232

3333
## Available Commands
3434

35-
> The application offers the following commands **via stdin**
36-
37-
TODO tty in docker and k8s
35+
> **_NOTE:_** The application offers the following commands **via stdin**
3836
3937
| Command | Description |
4038
| ------------------- | ------------------------------------------------------------------- |
@@ -50,115 +48,133 @@ TODO tty in docker and k8s
5048
| `request <url>` | Request a URL, e.g., `request https://www.kubermatic.com/` |
5149
| `delay / <seconds>` | Set delay for the root endpoint (`/`) in seconds, e.g., `delay / 5` |
5250

51+
> **_INSIDE A CONTAINER_** If you want to send commands to the application you have to use of `docker attach my-training-application-container`. The container als has to have `tty` enabled.
52+
53+
> **_INSIDE A POD_** If you want to send commands to the application you have have to use of `kubectl attach -it training-application-pod` and have the following flags set in the pod manifest:
54+
55+
```yaml
56+
apiVersion: v1
57+
kind: Pod
58+
metadata:
59+
name: training-application
60+
spec:
61+
containers:
62+
- name: training-application
63+
image: quay.io/kubermatic-labs/training-application:3.0.0
64+
imagePullPolicy: Always
65+
tty: true # <= add those flags
66+
stdin: true # <= add those flags
67+
ports:
68+
- name: http
69+
containerPort: 8080
70+
```
71+
5372
## Configuring the application
5473
5574
### `configFilePath`
5675

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` |
76+
- **Description**: Path to the config file
77+
- **Type**: string
78+
- **Default Value**: "./training-application.conf"
79+
- **Usage**: application arg, you can set this via eg `./training-application --configFilePath my.conf`
6280

6381
### `alive`
6482

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` |
83+
- **Description**: Flag to indicate the applications liveness
84+
- **Type**: bool
85+
- **Default Value**: true
86+
- **Usage**: configurable via the commands `set alive` and `set dead`
7187

7288
### `ready`
7389

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` |
90+
- **Description**: Flag to indicate the applications readiness
91+
- **Type**: bool
92+
- **Default Value**: false
93+
- **Usage**: true after `startUpDelaySeconds` , false on graceful shutdown; configurable via the commands `set ready` and `set unready`
8094

8195
### `name`
8296

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` |
97+
- **Description**: The name of the application
98+
- **Type**: string
99+
- **Default Value**: "not set"
100+
- **Usage**: via config file or via the environment variable `APP_NAME`
89101

90102
### `version`
91103

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` |
104+
- **Description**: The version of the application
105+
- **Type**: string
106+
- **Default Value**: "not set"
107+
- **Usage**: via config file or via the environment variable `APP_VERSION`
98108

99109
### `message`
100110

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` |
111+
- **Description**: A message to be shown on the root endpoint
112+
- **Type**: string
113+
- **Default Value**: "not set
114+
- **Usage**: via config file or via the environment variable `APP_MESSAGE`
107115

108116
### `color`
109117

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` |
118+
- **Description**: The background color of the root endpoint
119+
- **Type**: string
120+
- **Default Value**: "not set"
121+
- **Usage**: via config file or via the environment variable `APP_COLOR`
116122

117123
### `rootDelaySeconds`
118124

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+
- **Description**: For delaying requests to the root endpoint
126+
- **Type**: int
127+
- **Default Value**: 0
128+
- **Usage**: via config file or via the command `delay / <seconds>`, eg "delay / 10"
125129

126130
### `startUpDelaySeconds`
127131

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` |
132+
- **Description**: Time the application will take to start
133+
- **Type**: int
134+
- **Default Value**: 0
135+
- **Usage**: via config file
134136

135137
### `tearDownDelaySeconds`
136138

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` |
139+
- **Description**: Time the application will take to gracefully shut down
140+
- **Type**: int
141+
- **Default Value**: 0
142+
- **Usage**: via config file
143143

144144
### `logToFileOnly`
145145

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 |
146+
- **Description**: Log **only** to the file named `training-application.log`, if set to true no logging to stdout will happen
147+
- **Type**: bool
148+
- **Default Value**: false
149+
- **Usage**: via config file
152150

153151
### `catMode`
154152

155-
- **Description**:
156-
- **Type**:
157-
- **Default Value**:
158-
- **Usage**:
153+
- **Description**: Flag to get cute cat images in the root endpoint
154+
- **Type**: bool
155+
- **Default Value**: false
156+
- **Usage**: via config file
159157

160-
| Flag to get cute cat images in the rood endpoint | bool | false | | via config file |
158+
## Building the application
161159

162-
## Running the application
160+
```bash
161+
make build
162+
```
163163

164-
## Building the application
164+
## Running the application natively
165+
166+
```bash
167+
make run
168+
```
169+
170+
## Building the Image
171+
172+
```bash
173+
make docker-build
174+
```
175+
176+
## Running the Image
177+
178+
```bash
179+
make docker-run
180+
```

pod.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: training-application
5+
spec:
6+
containers:
7+
- name: training-application
8+
image: quay.io/kubermatic-labs/training-application:3.0.0
9+
imagePullPolicy: Always
10+
tty: true
11+
stdin: true
12+
ports:
13+
- name: http
14+
containerPort: 8080

src/config.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ type appConfig struct {
2323
applicationVersion string
2424
applicationMessage string
2525
color string
26-
nodeName string
27-
containerName string
28-
podNamespace string
29-
podName string
30-
podIP string
3126
logToFileOnly bool
3227
catImageUrl string
3328
}
@@ -45,11 +40,6 @@ func (appConfig *appConfig) logAppConfig() {
4540
log.Infof(" Application message: %s", appConfig.applicationMessage)
4641
log.Infof(" color: %s", appConfig.color)
4742
log.Infof(" logToFileOnly: %v", appConfig.logToFileOnly)
48-
log.Infof(" nodeName: %s", appConfig.nodeName)
49-
log.Infof(" containerName: %s", appConfig.containerName)
50-
log.Infof(" podNamespace: %s", appConfig.podNamespace)
51-
log.Infof(" podName: %s", appConfig.podName)
52-
log.Infof(" podIP: %s", appConfig.podIP)
5343
log.Infof(" catImageUrl: %s", appConfig.catImageUrl)
5444
}
5545

@@ -82,14 +72,9 @@ func (appConfig *appConfig) initAppConfig(isReady bool) {
8272
appConfig.applicationMessage = getAppConfigStringValue(fileConfig, "message", "APP_MESSAGE", "not set")
8373
appConfig.color = getAppConfigStringValue(fileConfig, "color", "APP_COLOR", "not set")
8474
appConfig.logToFileOnly = getAppConfigBoolValue(fileConfig, "logToFileOnly", "", false)
85-
appConfig.rootDelaySeconds = getAppConfigIntValue(fileConfig, "rootDelaySeconds", "APP_ROOT_DELAY_SECONDS", 0)
86-
appConfig.startUpDelaySeconds = getAppConfigIntValue(fileConfig, "startUpDelaySeconds", "APP_START_UP_DELAY_SECONDS", 0)
87-
appConfig.tearDownDelaySeconds = getAppConfigIntValue(fileConfig, "tearDownDelaySeconds", "APP_TEAR_DOWN_DELAY_SECONDS", 0)
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", "")
75+
appConfig.rootDelaySeconds = getAppConfigIntValue(fileConfig, "rootDelaySeconds", "", 0)
76+
appConfig.startUpDelaySeconds = getAppConfigIntValue(fileConfig, "startUpDelaySeconds", "", 0)
77+
appConfig.tearDownDelaySeconds = getAppConfigIntValue(fileConfig, "tearDownDelaySeconds", "", 0)
9378
catMode := getAppConfigBoolValue(fileConfig, "catMode", "", false)
9479
if catMode {
9580
appConfig.catImageUrl, err = getCat()

src/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ func main() {
5050

5151
server := newServer(config)
5252

53-
log.Infof("Application started with PID %d, listenting on port 8080", os.Getpid())
53+
hostName, _ := os.Hostname()
54+
log.Infof("Application started with PID %d, UID %d on host with name %s; listenting on port 8080", os.Getpid(), os.Getuid(), hostName)
5455
config.ready = true
5556
log.Info("Application set to ready")
5657
log.Info("For getting help, type 'help'")

src/server.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ func (s *server) handleRoot(w http.ResponseWriter, r *http.Request) {
4949
fmt.Fprint(w, "<!DOCTYPE html><htlml>")
5050
fmt.Fprintf(w, "<head><title>%s %s</title></head>", s.config.applicationName, s.config.applicationVersion)
5151
fmt.Fprintf(w, "<body style='background-color:%s;'>", s.config.color)
52-
if s.config.rootDelaySeconds > 0 {
53-
fmt.Fprintf(w, "(Response was delayed for %d seconds)", s.config.rootDelaySeconds)
54-
}
55-
fmt.Fprintf(w, "Application Name: %s<br>", s.config.applicationName)
52+
fmt.Fprintf(w, "<h1>%s</h1>", s.config.applicationName)
53+
fmt.Fprint(w, "<h2>Configuration</h2>")
5654
fmt.Fprintf(w, "Application Version: %s<br>", s.config.applicationVersion)
5755
fmt.Fprintf(w, "Application Message: %s<br>", s.config.applicationMessage)
5856
fmt.Fprintf(w, "Application Liveness: %t<br>", s.config.alive)
@@ -61,10 +59,17 @@ func (s *server) handleRoot(w http.ResponseWriter, r *http.Request) {
6159
fmt.Fprintf(w, "Seconds needed for startup: %d<br>", s.config.startUpDelaySeconds)
6260
fmt.Fprintf(w, "Seconds needed for teardown: %d<br>", s.config.tearDownDelaySeconds)
6361
fmt.Fprintf(w, "Only log to file: %v<br>", s.config.logToFileOnly)
64-
fmt.Fprintf(w, "Process ID of the application: %d<br>", os.Getpid())
62+
63+
fmt.Fprint(w, "<h2>Tech Details</h2>")
64+
fmt.Fprintf(w, "Process Id of the application: %d<br>", os.Getpid())
65+
fmt.Fprintf(w, "User Id of the application: %d<br>", os.Getuid())
66+
hostName, _ := os.Hostname()
67+
fmt.Fprintf(w, "Hostname: %s<br>", hostName)
68+
6569
if s.config.catImageUrl != "" {
6670
fmt.Fprintf(w, "<img src='%s' width='500px'></img>", s.config.catImageUrl)
6771
}
72+
6873
fmt.Fprint(w, "</body></htlml>")
6974
}
7075

todo.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
# todos
22

3-
## later
3+
## stuff
44

55
- pass in version into docker build?
66
- github action => is it save to put quay credentials in public repo
77
- write unit tests to ensure training usecases work (KFD, KSM)
88

9-
## lint
9+
### k8s meta info without downward api
1010

11-
### go code
11+
- serviceaccount
12+
- nodeName
13+
- podNamespace
14+
- podName
15+
- podIP
16+
17+
### lint
18+
19+
#### go code
1220

1321
- fix remaining linter issues and add dep from build step in makefile
1422

15-
### docker build
23+
#### docker build
1624

1725
- fix remaining linter issues and add dep from build step in makefile
1826

27+
### packaging
28+
29+
- linux service (for LF training)
30+
- compose
31+
- k8s
32+
- helm
33+
1934
## bugs
2035

2136
### leak cpu
@@ -29,11 +44,3 @@ recheck if istio really calls the readiness endpoint => WTF?!?!?!
2944
liveness and readiness probes logging is info too much => go smaller?
3045
make log level customizable
3146
do I need the caller? eg if the request is coming from k8s or istio?
32-
33-
## now
34-
35-
### TODO add configuration possibilities into readme
36-
37-
- app.conf
38-
- env vars
39-
- bin params

0 commit comments

Comments
 (0)