-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Package] [WorkerK8S] Implement Gopher Worker (#103)
* Feat [Package] [WorkerK8S] Constant - [+] chore(constant.go): add new constants for HOME, kube, Config, errconfig, cannotcreatek8s - [+] feat(constant.go): add new constants for FetchingPods, PodsFetched, ProcessingPods - [+] feat(constant.go): add new constants for TaskLabelKey, TaskCheckHealth, TaskGetPod, TaskFetchPods, TaskProcessPod * Feat [Package] [WorkerK8S] Module - [+] chore(go.mod): add github.com/imdario/mergo v0.3.6 as an indirect dependency - [+] chore(go.sum): add github.com/imdario/mergo v0.3.6 to go.sum as a direct dependency - [+] chore(go.mod): add github.com/spf13/pflag v1.0.5 as an indirect dependency - [+] chore(go.sum): add github.com/spf13/pflag v1.0.5 to go.sum as a direct dependency * Feat [Package] [WorkerK8S] Internal Setup - [+] fix(internal.go): fix error handling and add support for kubeconfig file outside the cluster - [+] feat(internal.go): add support for using the current context in kubeconfig * Feat [Package] [WorkerK8S] Zap Logger - [+] feat(logger.go): add logger functionality to workerk8s package - [+] fix(logger.go): fix logInfoWithEmoji and logErrorWithEmoji functions to include emoji and context in log message - [+] feat(logger.go): add createLogFields function to create log fields with operation, namespace, and additional info * [Package] [WorkerK8S] Update Docs & Implement Zap Logger - [+] feat(workerk8s): add structured logging to Worker function - [+] feat(workerk8s): add structured logging to RunWorkers function - [+] fix(workerk8s): fix log messages in getPods function - [+] fix(workerk8s): fix log messages in processPods function - [+] chore(workerk8s): update TODO list in docs.go - [+] chore(workerk8s): update enhancements section in docs.go
- Loading branch information
1 parent
548b068
commit 7ba2e6e
Showing
8 changed files
with
114 additions
and
15 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
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
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,38 @@ | ||
package workerk8s | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
// Logger is a package-level variable to access the zap logger throughout the handlers package. | ||
// It is intended to be used by other functions within the package for logging purposes. | ||
var Logger *zap.Logger | ||
|
||
// SetLogger sets the logger instance for the package. | ||
func SetLogger(logger *zap.Logger) { | ||
Logger = logger | ||
} | ||
|
||
// logInfoWithEmoji logs an informational message with given emoji, context, and fields. | ||
func logInfoWithEmoji(emoji string, context string, fields ...zap.Field) { | ||
Logger.Info(emoji+" "+context, fields...) | ||
} | ||
|
||
// logErrorWithEmoji logs an error message with given emoji, context, and fields. | ||
func logErrorWithEmoji(emoji string, context string, fields ...zap.Field) { | ||
Logger.Error(emoji+" "+context, fields...) | ||
} | ||
|
||
// createLogFields creates a slice of zap.Field with the operation and additional info. | ||
func createLogFields(operation string, namespace string, infos ...string) []zap.Field { | ||
fields := []zap.Field{ | ||
zap.String("operation", operation), | ||
zap.String("namespace", namespace), | ||
} | ||
for i, info := range infos { | ||
fields = append(fields, zap.String(fmt.Sprintf("info%d", i+1), info)) | ||
} | ||
return fields | ||
} |
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