Skip to content

Commit 023a986

Browse files
[release-0.3] Improved Scripts and Logs (#131)
* improve scripts, silent logs * improve scripts, silent logs * improve scripts, silent logs Co-authored-by: David Hadas <david.hadas@gmail.com>
1 parent 5fa768d commit 023a986

File tree

10 files changed

+61
-51
lines changed

10 files changed

+61
-51
lines changed

cmd/guard-service/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ func main() {
245245
// start a mainLoop
246246
go l.mainEventLoop(quit)
247247

248+
if env.GuardServiceAuth {
249+
pi.Log.Infof("Token turned on - clients identity is confirmed")
250+
} else {
251+
pi.Log.Infof("Token turned off - clients identity is not confirmed")
252+
}
253+
248254
if env.GuardServiceTls {
249255
pi.Log.Infof("TLS turned on")
250256
srv := &http.Server{
@@ -269,6 +275,7 @@ func main() {
269275
pi.Log.Infof("TLS turned off")
270276
err = http.ListenAndServe(target, mux)
271277
}
278+
272279
pi.Log.Infof("Using target: %s - Failed to start %v", target, err)
273280
quit <- "ListenAndServe failed"
274281
}

config/deploy/guard-service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
- name: GUARD_SERVICE_AUTH
3838
value: "false"
3939
- name: GUARD_SERVICE_LOG_LEVEL
40-
value: "debug"
40+
value: "info"
4141
---
4242
apiVersion: v1
4343
kind: Service

hack/installUsingOperatorWithTLS.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
18-
# Set the ROOT_CA and token audiences
19-
2017
echo "Copy the certificate to file"
2118
ROOTCA="$(mktemp)"
2219
FILENAME=`basename $ROOTCA`
@@ -28,6 +25,7 @@ CERT=`kubectl create cm config-deployment --from-file $ROOTCA -o json --dry-run=
2825
echo "cleanup"
2926
rm $ROOTCA
3027

28+
echo "Apply new Knative Operator configuration"
3129
kubectl apply --filename - <<EOF
3230
apiVersion: v1
3331
kind: Namespace

hack/installUsingOperatorWithoutTLS.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2022 The Knative Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
echo "Apply new Knative Operator configuration"
118
kubectl apply --filename - <<EOF
219
apiVersion: v1
320
kind: Namespace

hack/setTLS.sh

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,23 @@
1717

1818
# Set the ROOT_CA and token audiences
1919

20-
echo "Copy the certificate to file"
20+
echo "Add TLS and Tokens to guard-service"
21+
kubectl patch deployment guard-service -n knative-serving -p '{"spec":{"template":{"spec":{"containers":[{"name":"guard-service","env":[{"name": "GUARD_SERVICE_TLS", "value": "true"}, {"name": "GUARD_SERVICE_AUTH", "value": "true"}]}]}}}}'
22+
23+
echo "Copy the certificate to a temporary file"
2124
ROOTCA="$(mktemp)"
2225
FILENAME=`basename $ROOTCA`
2326
kubectl get secret -n knative-serving knative-serving-certs -o json| jq -r '.data."ca-cert.pem"' | base64 -d > $ROOTCA
2427

25-
echo "Create a temporary config-deployment configmap with the certificate"
28+
echo "Get the certificate in a configmap friendly form"
2629
CERT=`kubectl create cm config-deployment --from-file $ROOTCA -o json --dry-run=client |jq .data.\"$FILENAME\"`
2730

28-
echo "Get the current config-deployment configmap"
29-
CURRENT="$(mktemp)"
30-
kubectl get cm config-deployment -n knative-serving -o json | jq 'del(.data, .binaryData | ."queue-sidecar-token-audiences", ."queue-sidecar-rootca" )' > $CURRENT
31-
32-
echo "Add queue-sidecar-token-audiences"
33-
AUDIENCES="$(mktemp)"
34-
jq '.data |= . + { "queue-sidecar-token-audiences": "guard-service"}' $CURRENT > $AUDIENCES
35-
36-
echo "Join the two config-deployment configmaps into one"
37-
MERGED="$(mktemp)"
38-
jq --arg cert "${CERT}" '.data |= . + { "queue-sidecar-rootca": $cert}' $AUDIENCES > $MERGED
39-
40-
echo "Apply the joined config-deployment configmap"
41-
kubectl apply -f $MERGED -n knative-serving
31+
echo "Add TLS and Tokens to config-deployment configmap"
32+
kubectl patch cm config-deployment -n knative-serving -p '{"data":{"queue-sidecar-token-audiences": "guard-service", "queue-sidecar-rootca": '"$CERT"'}}'
4233

4334
echo "cleanup"
44-
rm $MERGED $AUDIENCES $ROOTCA $CURRENT
35+
rm $ROOTCA
4536

4637
echo "Results:"
4738
kubectl get cm config-deployment -n knative-serving -o json|jq '.data'
39+
kubectl get deployment guard-service -n knative-serving -o json|jq .spec.template.spec.containers[0].env

hack/unsetTLS.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717

1818
# Unset the ROOT_CA and token audiences
1919

20-
echo "Get the current config-deployment configmap"
21-
CURRENT="$(mktemp)"
22-
kubectl get cm config-deployment -n knative-serving -o json | jq 'del(.data, .binaryData | ."queue-sidecar-token-audiences", ."queue-sidecar-rootca" )' > $CURRENT
20+
echo "Remove TLS and Tokens from guard-service"
21+
kubectl patch deployment guard-service -n knative-serving -p '{"spec":{"template":{"spec":{"containers":[{"name":"guard-service","env":[{"name": "GUARD_SERVICE_TLS", "value": "false"}, {"name": "GUARD_SERVICE_AUTH", "value": "false"}]}]}}}}'
2322

24-
echo "Apply the joined config-deployment configmap"
25-
kubectl apply -f $CURRENT -n knative-serving
26-
27-
echo "cleanup"
28-
rm $CURRENT
23+
echo "Remove TLS and Tokens from config-deployment configmap"
24+
kubectl patch cm config-deployment -n knative-serving -p '{"data":{"queue-sidecar-token-audiences": "", "queue-sidecar-rootca": ""}}'
2925

3026
echo "Results:"
3127
kubectl get cm config-deployment -n knative-serving -o json|jq '.data'
28+
kubectl get deployment guard-service -n knative-serving -o json|jq .spec.template.spec.containers[0].env

pkg/guard-gate/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (hc *httpClient) ReadToken(audience string) {
7171
b, err := os.ReadFile(path.Join("/var/run/secrets/tokens", audience))
7272

7373
if err != nil {
74-
pi.Log.Infof("Token %s is missing - working without token", audience)
74+
pi.Log.Debugf("Token %s is missing - working without token", audience)
7575
hc.missingToken = true
7676
return
7777
}
@@ -112,7 +112,6 @@ func (srv *gateClient) initKubeMgr() {
112112

113113
func (srv *gateClient) initHttpClient(certPool *x509.CertPool) {
114114
client := new(httpClient)
115-
pi.Log.Infof("initHttpClient using ServerName %s\n", certificates.FakeDnsName)
116115
client.client.Transport = &http.Transport{
117116
MaxConnsPerHost: 0,
118117
MaxIdleConns: 0,
@@ -158,7 +157,7 @@ func (srv *gateClient) reportPile() {
158157
query.Add("cm", "true")
159158
}
160159
req.URL.RawQuery = query.Encode()
161-
pi.Log.Infof("Reporting a pile with pileCount %d records to guard-service", srv.pile.Count)
160+
pi.Log.Debugf("Reporting a pile with pileCount %d records to guard-service", srv.pile.Count)
162161

163162
res, postErr := srv.httpClient.Do(req)
164163
if postErr != nil {

pkg/guard-gate/gate.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type plug struct {
5454
}
5555

5656
func (p *plug) Shutdown() {
57-
pi.Log.Infof("%s: Shutdown", p.name)
57+
pi.Log.Debugf("%s: Shutdown", p.name)
5858
p.gateState.flushPile()
5959
}
6060

@@ -124,8 +124,7 @@ func (p *plug) guardMainEventLoop(ctx context.Context) {
124124
p.reportPileTicker.Stop()
125125
p.podMonitorTicker.Stop()
126126
p.gateState.flushPile()
127-
pi.Log.Infof("Statistics: %s", p.gateState.stat.Log())
128-
pi.Log.Infof("%s Done!", plugName)
127+
pi.Log.Infof("%s: Done with the following statistics: %s", plugName, p.gateState.stat.Log())
129128
}()
130129

131130
for {
@@ -151,6 +150,7 @@ func (p *plug) guardMainEventLoop(ctx context.Context) {
151150
func (p *plug) preInit(ctx context.Context, c map[string]string, sid string, ns string, logger pi.Logger) (context.Context, context.CancelFunc) {
152151
var ok bool
153152
var v string
153+
var loadInterval, pileInterval, monitorInterval string
154154

155155
ctx, cancelFunction := context.WithCancel(ctx)
156156

@@ -176,21 +176,22 @@ func (p *plug) preInit(ctx context.Context, c map[string]string, sid string, ns
176176
if v, ok = c["monitor-pod"]; ok && !strings.EqualFold(v, "true") {
177177
monitorPod = false
178178
}
179-
p.guardianLoadTicker = utils.NewTicker(utils.MinimumInterval)
180-
p.reportPileTicker = utils.NewTicker(utils.MinimumInterval)
181-
p.podMonitorTicker = utils.NewTicker(utils.MinimumInterval)
182-
p.guardianLoadTicker.Parse(c["guardian-load-interval"], guardianLoadIntervalDefault)
183-
p.reportPileTicker.Parse(c["report-pile-interval"], reportPileIntervalDefault)
184-
p.podMonitorTicker.Parse(c["pod-monitor-interval"], podMonitorIntervalDefault)
185-
186-
pi.Log.Debugf("guard-gate configuration: sid=%s, ns=%s, useCm=%t, guardUrl=%s, p.monitorPod=%t, guardian-load-interval %v, report-pile-interval %v, pod-monitor-interval %v",
187-
sid, ns, useCm, guardServiceUrl, monitorPod, c["guardian-load-interval"], c["report-pile-interval"], c["pod-monitor-interval"])
188-
} else {
189-
p.guardianLoadTicker.Parse("", guardianLoadIntervalDefault)
190-
p.reportPileTicker.Parse("", reportPileIntervalDefault)
191-
p.podMonitorTicker.Parse("", podMonitorIntervalDefault)
179+
loadInterval = c["guardian-load-interval"]
180+
pileInterval = c["report-pile-interval"]
181+
monitorInterval = c["pod-monitor-interval"]
192182
}
193183

184+
p.guardianLoadTicker = utils.NewTicker(utils.MinimumInterval)
185+
p.reportPileTicker = utils.NewTicker(utils.MinimumInterval)
186+
p.podMonitorTicker = utils.NewTicker(utils.MinimumInterval)
187+
188+
p.guardianLoadTicker.Parse(loadInterval, guardianLoadIntervalDefault)
189+
p.reportPileTicker.Parse(pileInterval, reportPileIntervalDefault)
190+
p.podMonitorTicker.Parse(monitorInterval, podMonitorIntervalDefault)
191+
192+
pi.Log.Debugf("guard-gate configuration: sid=%s, ns=%s, useCm=%t, guardUrl=%s, p.monitorPod=%t, guardian-load-interval %v, report-pile-interval %v, pod-monitor-interval %v",
193+
sid, ns, useCm, guardServiceUrl, monitorPod, loadInterval, pileInterval, monitorInterval)
194+
194195
// serviceName should never be "ns.{namespace}" as this is a reserved name
195196
if strings.HasPrefix(sid, "ns.") {
196197
// mandatory
@@ -199,7 +200,6 @@ func (p *plug) preInit(ctx context.Context, c map[string]string, sid string, ns
199200

200201
p.gateState = new(gateState)
201202
p.gateState.init(cancelFunction, monitorPod, guardServiceUrl, sid, ns, useCm)
202-
pi.Log.Infof("guardServiceUrl %s", guardServiceUrl)
203203
return ctx, cancelFunction
204204
}
205205

pkg/guard-gate/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (gs *gateState) init(cancelFunc context.CancelFunc, monitorPod bool, guardS
5656

5757
if rootCA := os.Getenv("ROOT_CA"); rootCA != "" {
5858
if ok := gs.certPool.AppendCertsFromPEM([]byte(rootCA)); ok {
59-
pi.Log.Infof("TLS: Success adding ROOT_CA")
59+
pi.Log.Debugf("TLS: Success adding ROOT_CA")
6060
} else {
6161
pi.Log.Infof("TLS: Failed to AppendCertsFromPEM from ROOT_CA")
6262
}

pkg/guard-kubemgr/watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (k *KubeMgr) WatchOnce(ns string, cmFlag bool, set func(ns string, sid stri
126126
gdata := []byte(cm.Data["Guardian"])
127127
jsonErr := json.Unmarshal(gdata, g)
128128
if jsonErr != nil {
129-
pi.Log.Infof("wsgate getConfig: unmarshel error %v\n", jsonErr)
129+
pi.Log.Infof("wsgate getConfig sid=%s, ns=%s: unmarshel error %v\n", sid, ns, jsonErr)
130130
set(ns, sid, cmFlag, nil)
131131
continue
132132
}

0 commit comments

Comments
 (0)