Skip to content

Commit

Permalink
Merge pull request wildfly#243 from yersan/issue-239
Browse files Browse the repository at this point in the history
[issue-239] Apply go 1.19.x formatter
  • Loading branch information
jmesnil authored Jun 21, 2023
2 parents 4ec0412 + d55f4b3 commit e8d4ba8
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 42 deletions.
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ controller-gen: ## Download controller-gen locally if necessary.
KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@latest)

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
Expand All @@ -230,12 +230,8 @@ PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on go install $(2) ;\
}
endef

Expand Down
16 changes: 10 additions & 6 deletions controllers/transaction_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ func (r *WildFlyServerReconciler) updatePodLabel(w *wildflyv1alpha1.WildFlyServe
}

// processTransactionRecoveryScaleDown runs transaction recovery on provided number of pods
// mustReconcile returns int constant; 'requeueNow' if the reconcile requeue loop should be called as soon as possible,
// 'requeueLater' if requeue loop is needed but it could be delayed, 'requeueOff' if requeue loop is not necessary
// err reports error which occurs during method processing
//
// mustReconcile returns int constant; 'requeueNow' if the reconcile requeue loop should be called as soon as possible,
// 'requeueLater' if requeue loop is needed but it could be delayed, 'requeueOff' if requeue loop is not necessary
// err reports error which occurs during method processing
func (r *WildFlyServerReconciler) processTransactionRecoveryScaleDown(reqLogger logr.Logger, w *wildflyv1alpha1.WildFlyServer,
numberOfPodsToScaleDown int, podList *corev1.PodList) (mustReconcile int, err error) {

Expand Down Expand Up @@ -412,7 +413,8 @@ func (r *WildFlyServerReconciler) processTransactionRecoveryScaleDown(reqLogger
}

// setLabelAsDisabled returns true when label was updated or an issue on update requires recociliation
// returns error when an error occurs during processing, otherwise if no error occurs nil is returned
//
// returns error when an error occurs during processing, otherwise if no error occurs nil is returned
func (r *WildFlyServerReconciler) setLabelAsDisabled(w *wildflyv1alpha1.WildFlyServer, reqLogger logr.Logger, labelName string, numberOfPodsToScaleDown int,
podList *corev1.PodList) (bool, error) {
wildflyServerNumberOfPods := len(podList.Items)
Expand Down Expand Up @@ -446,7 +448,8 @@ func (r *WildFlyServerReconciler) setLabelAsDisabled(w *wildflyv1alpha1.WildFlyS
}

// isJDBCLogStoreInUse executes jboss CLI command to search if transctions are saved in the JDBC object store
// i.e. the transaction log is not stored in the file system but out of the StatefulSet controlled $JBOSS_HOME /data directory
//
// i.e. the transaction log is not stored in the file system but out of the StatefulSet controlled $JBOSS_HOME /data directory
func isJDBCLogStoreInUse(pod *corev1.Pod) (bool, error) {
isJDBCTxnStore, err := wfly.ExecuteAndGetResult(pod, wfly.MgmtOpTxnCheckJdbcStore)
if err != nil {
Expand All @@ -460,7 +463,8 @@ func isJDBCLogStoreInUse(pod *corev1.Pod) (bool, error) {
}

// skipRecoveryAndForceScaleDown serves to sets the scaling down pods as being processed by recovery and mark them
// to be deleted by statefulset update. This is used for cases when recovery process should be skipped.
//
// to be deleted by statefulset update. This is used for cases when recovery process should be skipped.
func (r *WildFlyServerReconciler) skipRecoveryAndForceScaleDown(w *wildflyv1alpha1.WildFlyServer, totalNumberOfPods int,
numberOfPodsToScaleDown int, podList *corev1.PodList) (mustReconcile int, err error) {
log := r.Log
Expand Down
6 changes: 4 additions & 2 deletions controllers/wildflyserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ func matches(container *corev1.Container, envVar corev1.EnvVar) bool {
}

// GetPodsForWildFly lists pods which belongs to the WildFly server
// the pods are differentiated based on the selectors
//
// the pods are differentiated based on the selectors
func GetPodsForWildFly(r *WildFlyServerReconciler, w *wildflyv1alpha1.WildFlyServer) (*corev1.PodList, error) {
podList := &corev1.PodList{}

Expand Down Expand Up @@ -511,7 +512,8 @@ func getPodStatus(pods []corev1.Pod, originalPodStatuses []wildflyv1alpha1.PodSt
}

// LabelsForWildFly return a map of labels that are used for identification
// of objects belonging to the particular WildflyServer instance
//
// of objects belonging to the particular WildflyServer instance
func LabelsForWildFly(w *wildflyv1alpha1.WildFlyServer) map[string]string {
labels := make(map[string]string)
labels["app.kubernetes.io/name"] = w.Name
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func AdminServiceName(w *wildflyv1alpha1.WildFlyServer) string {
// ClusterServiceName returns the name of the cluster service.
//
// The service remains named with the -loadbalancer suffix for backwards compatibility
/// even if it is now a ClusterIP service.
// / even if it is now a ClusterIP service.
func ClusterServiceName(w *wildflyv1alpha1.WildFlyServer) string {
return w.Name + "-loadbalancer"
}
31 changes: 19 additions & 12 deletions pkg/util/go_utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var (
)

// ContainsInMap returns true if the map m contains at least one of the string
// presented as argument `vals`, otherwise false is returned
//
// presented as argument `vals`, otherwise false is returned
func ContainsInMap(m map[string]string, vals ...string) bool {
for _, x := range m {
for _, v := range vals {
Expand All @@ -32,7 +33,8 @@ func ContainsInMap(m map[string]string, vals ...string) bool {
}

// ContainsInList returns true if the string s is included in the list,
// otherwise false is returned
//
// otherwise false is returned
func ContainsInList(list []string, s string) bool {
for _, v := range list {
if v == s {
Expand All @@ -43,7 +45,8 @@ func ContainsInList(list []string, s string) bool {
}

// RemoveFromList iterates over the list and removes all occurences
// of the string s. The list without the s strings is returned.
//
// of the string s. The list without the s strings is returned.
func RemoveFromList(list []string, s string) []string {
for i, v := range list {
if v == s {
Expand All @@ -54,7 +57,8 @@ func RemoveFromList(list []string, s string) []string {
}

// SortPodListByName sorts the pod list by number in the name
// expecting the format which the StatefulSet works with which is `<podname>-<number>`
//
// expecting the format which the StatefulSet works with which is `<podname>-<number>`
func SortPodListByName(podList *corev1.PodList) *corev1.PodList {
sort.SliceStable(podList.Items, func(i, j int) bool {
reOut1 := regexpPatternEndsWithNumber.FindStringSubmatch(podList.Items[i].ObjectMeta.Name)
Expand All @@ -80,7 +84,8 @@ func SortPodListByName(podList *corev1.PodList) *corev1.PodList {
}

// CopyMap duplicates map as it creates new map and puts there all the
// key value pairs that were included in the first map
//
// key value pairs that were included in the first map
func CopyMap(originalMap map[string]string) map[string]string {
return MapMerge(originalMap, nil)
}
Expand All @@ -101,7 +106,8 @@ func MapMerge(firstMap map[string]string, secondOverwritingMap map[string]string
}

// GetEnvAsInt returns defined environment variable as an integer
// or default value is returned if the env var is not configured
//
// or default value is returned if the env var is not configured
func GetEnvAsInt(key string, fallbackInteger int64) int64 {
valueStr, ok := os.LookupEnv(key)
if ok {
Expand All @@ -114,12 +120,13 @@ func GetEnvAsInt(key string, fallbackInteger int64) int64 {
}

// GetEnvAsDuration returns defined environment variable as duration
// while it expects the environment variable contains the number defined in duration type
// defined as a third parameter. The result will be returned as duration.
// If env variable is not found then the default value as duration is returned (defined by the duration type)
// e.g. call 'GetEnvAsDuration("TIMEOUT", 10, time.Second)' means
// search for the TIMEOUT env variable and the value is expected being defined in seconds,
// if the env var is not found then returns duration of 10 seconds
//
// while it expects the environment variable contains the number defined in duration type
// defined as a third parameter. The result will be returned as duration.
// If env variable is not found then the default value as duration is returned (defined by the duration type)
// e.g. call 'GetEnvAsDuration("TIMEOUT", 10, time.Second)' means
// search for the TIMEOUT env variable and the value is expected being defined in seconds,
// if the env var is not found then returns duration of 10 seconds
func GetEnvAsDuration(key string, fallbackDurationAmount int64, durationType time.Duration) time.Duration {
valueAsInt := GetEnvAsInt(key, fallbackDurationAmount)
return time.Duration(valueAsInt) * durationType
Expand Down
11 changes: 7 additions & 4 deletions pkg/util/remote_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (RemoteOperationsStruct) Execute(pod *corev1.Pod, command string) (string,
}

// SocketConnect send a command (a string) to the defined hostname and port
// where it connects to with 'net.Dial' tcp connection
//
// where it connects to with 'net.Dial' tcp connection
func (RemoteOperationsStruct) SocketConnect(hostname string, port int32, command string) (string, error) {
// connect to socket
toConnectTo := fmt.Sprintf("%v:%v", hostname, port)
Expand All @@ -128,8 +129,9 @@ func (RemoteOperationsStruct) SocketConnect(hostname string, port int32, command
}

// ObtainLogLatestTimestamp reads log from pod and find out
// what is the latest log record at the time
// and returns time stamp of the record
//
// what is the latest log record at the time
// and returns time stamp of the record
func (RemoteOperationsStruct) ObtainLogLatestTimestamp(pod *corev1.Pod) (*time.Time, error) {
lineReader, err := readPodLog(pod, &tailOneLineLogOptions)
if err != nil {
Expand Down Expand Up @@ -159,7 +161,8 @@ func (RemoteOperationsStruct) ObtainLogLatestTimestamp(pod *corev1.Pod) (*time.T
}

// VerifyLogContainsRegexp checks if a line in the log from the pod matches the provided regexp
// the log could be limited to be taken from particular time further, when no time defined the log is not limited by time
//
// the log could be limited to be taken from particular time further, when no time defined the log is not limited by time
func (RemoteOperationsStruct) VerifyLogContainsRegexp(pod *corev1.Pod, logFromTime *time.Time, regexpLineCheck *regexp.Regexp) (string, error) {
timeLimitingPodLogOptions := corev1.PodLogOptions{}
if logFromTime != nil {
Expand Down
28 changes: 17 additions & 11 deletions pkg/util/wildfly_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func IsMgmtOutcomeSuccesful(jsonBody map[string]interface{}) bool {
}

// ExecuteMgmtOp executes WildFly managemnt operation represented as a string
// the execution runs as shh remote command with jboss-cli.sh executed on the pod
// returns the JSON as the return value from the operation
//
// the execution runs as shh remote command with jboss-cli.sh executed on the pod
// returns the JSON as the return value from the operation
func ExecuteMgmtOp(pod *corev1.Pod, mgmtOpString string) (map[string]interface{}, error) {
jbossCliCommand := fmt.Sprintf("${JBOSS_HOME}/bin/jboss-cli.sh --output-json -c --commands='%s'", mgmtOpString)
resString, err := RemoteOps.Execute(pod, jbossCliCommand)
Expand Down Expand Up @@ -86,7 +87,8 @@ func ExecuteMgmtOp(pod *corev1.Pod, mgmtOpString string) (map[string]interface{}
}

// decodeJSONBody takes the io.Reader (res) as expected to be representation of a JSON
// and decodes it to the form of the JSON type "native" to golang
//
// and decodes it to the form of the JSON type "native" to golang
func decodeJSON(reader *io.ReadCloser) (map[string]interface{}, error) {
var resJSON map[string]interface{}
err := json.NewDecoder(*reader).Decode(&resJSON)
Expand All @@ -97,7 +99,8 @@ func decodeJSON(reader *io.ReadCloser) (map[string]interface{}, error) {
}

// ReadJSONDataByIndex iterates over the JSON object to return
// data saved at the provided index. It returns json data as interface{}.
//
// data saved at the provided index. It returns json data as interface{}.
func ReadJSONDataByIndex(json interface{}, indexes ...string) interface{} {
jsonInProgress := json
for _, index := range indexes {
Expand Down Expand Up @@ -153,9 +156,10 @@ func GetTransactionRecoveryPort(pod *corev1.Pod) (int32, error) {
}

// ExecuteOpAndWaitForServerBeingReady executes WildFly management operation on the pod
// this operation is checked to succeed and then waits for the container is ready
// this method is assumed to be used for reload/restart operations
// returns error if execution was not processed successfully
//
// this operation is checked to succeed and then waits for the container is ready
// this method is assumed to be used for reload/restart operations
// returns error if execution was not processed successfully
func ExecuteOpAndWaitForServerBeingReady(reqLogger logr.Logger, mgmtOp string, pod *corev1.Pod) error {
podName := pod.ObjectMeta.Name

Expand Down Expand Up @@ -184,8 +188,9 @@ func ExecuteOpAndWaitForServerBeingReady(reqLogger logr.Logger, mgmtOp string, p
}

// IsAppServerRunningViaJBossCli runs JBoss CLI call to app server to find out if is in state 'running'
// if 'running' then returns true, otherwise false
// when false is returned then error contains a message with app server's state
//
// if 'running' then returns true, otherwise false
// when false is returned then error contains a message with app server's state
func IsAppServerRunningViaJBossCli(pod *corev1.Pod) (bool, error) {
jsonResult, err := ExecuteMgmtOp(pod, MgmtOpServerStateRead)
if err == nil {
Expand All @@ -210,8 +215,9 @@ func ListSubsystems(pod *corev1.Pod) ([]string, error) {
}

// ExecuteAndGetResult executes the JBoss CLI operation provided as the string in parameter 'managementOperation'
// It will be executed by call of 'jboss-cli.sh' at the particular pod.
// When succesful it returns the result part of the returned json, otherwise it returns nil with error describing failure details.
//
// It will be executed by call of 'jboss-cli.sh' at the particular pod.
// When succesful it returns the result part of the returned json, otherwise it returns nil with error describing failure details.
func ExecuteAndGetResult(pod *corev1.Pod, managementOperation string) (interface{}, error) {
podName := pod.ObjectMeta.Name
jsonResult, err := ExecuteMgmtOp(pod, managementOperation)
Expand Down

0 comments on commit e8d4ba8

Please sign in to comment.