forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPSTREAM: 96120: kubelet: Expose a simple Get-WinEvent shim on the ku…
…belet logs endpoint Provide an administrator a streaming view of event logs on Windows machines without them having to implement a client side reader. The kubelet API for querying the Linux journal is re-used for invoking the Get-WinEvent cmdlet in a PowerShell. Parameters that have no functional equivalence in Get-WinEvent are ignored when assembling the command. Only available to cluster admins.
- Loading branch information
1 parent
3d7e6c2
commit 1954664
Showing
6 changed files
with
134 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// +build linux | ||
|
||
package kubelet | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// getLoggingCmd returns the journalctl cmd and arguments for the given journalArgs and boot | ||
func getLoggingCmd(a *journalArgs, boot int) (string, []string) { | ||
args := []string{ | ||
"--utc", | ||
"--no-pager", | ||
} | ||
if len(a.Since) > 0 { | ||
args = append(args, "--since="+a.Since) | ||
} | ||
if len(a.Until) > 0 { | ||
args = append(args, "--until="+a.Until) | ||
} | ||
if a.Tail > 0 { | ||
args = append(args, "--pager-end", fmt.Sprintf("--lines=%d", a.Tail)) | ||
} | ||
if len(a.Format) > 0 { | ||
args = append(args, "--output="+a.Format) | ||
} | ||
for _, unit := range a.Units { | ||
if len(unit) > 0 { | ||
args = append(args, "--unit="+unit) | ||
} | ||
} | ||
if len(a.Pattern) > 0 { | ||
args = append(args, "--grep="+a.Pattern) | ||
args = append(args, fmt.Sprintf("--case-sensitive=%t", a.CaseSensitive)) | ||
} | ||
|
||
args = append(args, "--boot", fmt.Sprintf("%d", boot)) | ||
|
||
return "journalctl", args | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// +build !linux,!windows | ||
|
||
package kubelet | ||
|
||
// getLoggingCmd on unsupported operating systems returns the echo command and a warning message (as strings) | ||
func getLoggingCmd(a *journalArgs, boot int) (string, []string) { | ||
return "echo", []string{"Operating System Not Supported"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// +build windows | ||
|
||
package kubelet | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// getLoggingCmd returns the powershell cmd and arguments for the given journalArgs and boot | ||
func getLoggingCmd(a *journalArgs, boot int) (string, []string) { | ||
// The WinEvent log does not support querying by boot | ||
// Set the cmd to return true on windows in case boot is not 0 | ||
if boot != 0 { | ||
return "cd.", []string{} | ||
} | ||
|
||
args := []string{ | ||
"-NonInteractive", | ||
"-ExecutionPolicy", "Bypass", | ||
"-Command", | ||
} | ||
|
||
psCmd := "Get-WinEvent -FilterHashtable @{LogName='Application'" | ||
if len(a.Since) > 0 { | ||
psCmd += fmt.Sprintf("; StartTime='%s'", a.Since) | ||
} | ||
if len(a.Until) > 0 { | ||
psCmd += fmt.Sprintf("; EndTime='%s'", a.Until) | ||
} | ||
var units []string | ||
for _, unit := range a.Units { | ||
if len(unit) > 0 { | ||
units = append(units, "'"+unit+"'") | ||
} | ||
} | ||
if len(units) > 0 { | ||
psCmd += fmt.Sprintf("; ProviderName=%s", strings.Join(units, ",")) | ||
} | ||
psCmd += "}" | ||
if a.Tail > 0 { | ||
psCmd += fmt.Sprintf(" -MaxEvents %d", a.Tail) | ||
} | ||
psCmd += " | Sort-Object TimeCreated" | ||
if len(a.Pattern) > 0 { | ||
psCmd += fmt.Sprintf(" | Where-Object -Property Message -Match %s", a.Pattern) | ||
} | ||
psCmd += " | Format-Table -AutoSize -Wrap" | ||
|
||
args = append(args, psCmd) | ||
|
||
return "PowerShell.exe", args | ||
} |