Skip to content

Commit 8826909

Browse files
authored
Merge pull request #2995 from nirs/guestagent-startup
Improve guestagent startup error handling and logging
2 parents 0d9572b + f8b9e07 commit 8826909

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

pkg/guestagent/guestagent_linux.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,30 @@ func New(newTicker func() (<-chan time.Time, func()), iptablesIdle time.Duration
2828
}
2929

3030
auditClient, err := libaudit.NewMulticastAuditClient(nil)
31-
switch {
32-
// syscall.EPROTONOSUPPORT or syscall.EAFNOSUPPORT is returned when calling attempting to connect to NETLINK_AUDIT
33-
// on a kernel built without auditing support.
34-
// https://github.com/elastic/go-libaudit/blob/ec298e53a6841a1f7715abbc7122635622f349bd/audit.go#L112-L115
35-
case errors.Is(err, syscall.EPROTONOSUPPORT), errors.Is(err, syscall.EAFNOSUPPORT):
36-
return startGuestAgentRoutines(a, false)
37-
case !errors.Is(err, nil):
38-
return nil, err
31+
if err != nil {
32+
// syscall.EPROTONOSUPPORT or syscall.EAFNOSUPPORT is returned when calling attempting to connect to NETLINK_AUDIT
33+
// on a kernel built without auditing support.
34+
// https://github.com/elastic/go-libaudit/blob/ec298e53a6841a1f7715abbc7122635622f349bd/audit.go#L112-L115
35+
if !errors.Is(err, syscall.EPROTONOSUPPORT) && !errors.Is(err, syscall.EAFNOSUPPORT) {
36+
return nil, err
37+
}
38+
logrus.Infof("Auditing is not available: %s", err)
39+
return startGuestAgentRoutines(a, false), nil
3940
}
4041

41-
// syscall.EPERM is returned when using audit from a non-initial namespace
42-
// https://github.com/torvalds/linux/blob/633b47cb009d09dc8f4ba9cdb3a0ca138809c7c7/kernel/audit.c#L1054-L1057
4342
auditStatus, err := auditClient.GetStatus()
44-
switch {
45-
case errors.Is(err, syscall.EPERM):
46-
return startGuestAgentRoutines(a, false)
47-
case !errors.Is(err, nil):
48-
return nil, err
43+
if err != nil {
44+
// syscall.EPERM is returned when using audit from a non-initial namespace
45+
// https://github.com/torvalds/linux/blob/633b47cb009d09dc8f4ba9cdb3a0ca138809c7c7/kernel/audit.c#L1054-L1057
46+
if !errors.Is(err, syscall.EPERM) {
47+
return nil, err
48+
}
49+
logrus.Infof("Auditing is not permitted: %s", err)
50+
return startGuestAgentRoutines(a, false), nil
4951
}
5052

5153
if auditStatus.Enabled == 0 {
54+
logrus.Info("Enabling auditing")
5255
if err = auditClient.SetEnabled(true, libaudit.WaitForReply); err != nil {
5356
return nil, err
5457
}
@@ -66,22 +69,23 @@ func New(newTicker func() (<-chan time.Time, func()), iptablesIdle time.Duration
6669
} else {
6770
a.worthCheckingIPTables = true
6871
}
69-
return startGuestAgentRoutines(a, true)
72+
logrus.Infof("Auditing enabled (%d)", auditStatus.Enabled)
73+
return startGuestAgentRoutines(a, true), nil
7074
}
7175

7276
// startGuestAgentRoutines sets worthCheckingIPTables to true if auditing is not supported,
7377
// instead of using setWorthCheckingIPTablesRoutine to dynamically set the value.
7478
//
7579
// Auditing is not supported in a kernels and is not currently supported outside of the initial namespace, so does not work
7680
// from inside a container or WSL2 instance, for example.
77-
func startGuestAgentRoutines(a *agent, supportsAuditing bool) (*agent, error) {
81+
func startGuestAgentRoutines(a *agent, supportsAuditing bool) *agent {
7882
if !supportsAuditing {
7983
a.worthCheckingIPTables = true
8084
}
8185
go a.kubernetesServiceWatcher.Start()
8286
go a.fixSystemTimeSkew()
8387

84-
return a, nil
88+
return a
8589
}
8690

8791
type agent struct {
@@ -103,6 +107,7 @@ type agent struct {
103107
// setWorthCheckingIPTablesRoutine sets worthCheckingIPTables to be false
104108
// when no NETFILTER_CFG audit message was received for the iptablesIdle time.
105109
func (a *agent) setWorthCheckingIPTablesRoutine(auditClient *libaudit.AuditClient, iptablesIdle time.Duration) {
110+
logrus.Info("setWorthCheckingIPTablesRoutine(): monitoring netfilter audit events")
106111
var latestTrue time.Time
107112
go func() {
108113
for {
@@ -323,6 +328,7 @@ func (a *agent) Info(ctx context.Context) (*api.Info, error) {
323328
const deltaLimit = 2 * time.Second
324329

325330
func (a *agent) fixSystemTimeSkew() {
331+
logrus.Info("fixSystemTimeSkew(): monitoring system time skew")
326332
for {
327333
ok, err := timesync.HasRTC()
328334
if !ok {

pkg/guestagent/kubernetesservice/kubernetesservice.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (s *ServiceWatcher) getServiceInformer() cache.SharedIndexInformer {
5656
}
5757

5858
func (s *ServiceWatcher) Start() {
59+
logrus.Info("Monitoring kubernetes services")
5960
const retryInterval = 10 * time.Second
6061
const pollImmediately = false
6162
_ = wait.PollUntilContextCancel(context.TODO(), retryInterval, pollImmediately, func(ctx context.Context) (done bool, err error) {

0 commit comments

Comments
 (0)