Skip to content

Commit

Permalink
Replaced condition by state.
Browse files Browse the repository at this point in the history
Signed-off-by: Klaus Ma <[email protected]>
  • Loading branch information
Klaus Ma authored and k82cn committed Jan 16, 2019
1 parent 25a06ea commit 24ef641
Show file tree
Hide file tree
Showing 41 changed files with 3,281 additions and 162 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cli:
generate-code:
go build -o ${BIN_DIR}/deepcopy-gen ./cmd/deepcopy-gen/
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/batch/v1alpha1/ -O zz_generated.deepcopy
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/core/v1alpha1/ -O zz_generated.deepcopy

e2e-test:
./hack/run-e2e.sh
Expand Down
171 changes: 171 additions & 0 deletions cluster/lib/logging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/bin/bash

# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Controls verbosity of the script output and logging.
KUBE_VERBOSE="${KUBE_VERBOSE:-5}"

# Handler for when we exit automatically on an error.
# Borrowed from https://gist.github.com/ahendrix/7030300
kube::log::errexit() {
local err="${PIPESTATUS[@]}"

# If the shell we are in doesn't have errexit set (common in subshells) then
# don't dump stacks.
set +o | grep -qe "-o errexit" || return

set +o xtrace
local code="${1:-1}"
# Print out the stack trace described by $function_stack
if [ ${#FUNCNAME[@]} -gt 2 ]
then
kube::log::error "Call tree:"
for ((i=1;i<${#FUNCNAME[@]}-1;i++))
do
kube::log::error " $i: ${BASH_SOURCE[$i+1]}:${BASH_LINENO[$i]} ${FUNCNAME[$i]}(...)"
done
fi
kube::log::error_exit "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status $err" "${1:-1}" 1
}

kube::log::install_errexit() {
# trap ERR to provide an error handler whenever a command exits nonzero this
# is a more verbose version of set -o errexit
trap 'kube::log::errexit' ERR

# setting errtrace allows our ERR trap handler to be propagated to functions,
# expansions and subshells
set -o errtrace
}

# Print out the stack trace
#
# Args:
# $1 The number of stack frames to skip when printing.
kube::log::stack() {
local stack_skip=${1:-0}
stack_skip=$((stack_skip + 1))
if [[ ${#FUNCNAME[@]} -gt $stack_skip ]]; then
echo "Call stack:" >&2
local i
for ((i=1 ; i <= ${#FUNCNAME[@]} - $stack_skip ; i++))
do
local frame_no=$((i - 1 + stack_skip))
local source_file=${BASH_SOURCE[$frame_no]}
local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
local funcname=${FUNCNAME[$frame_no]}
echo " $i: ${source_file}:${source_lineno} ${funcname}(...)" >&2
done
fi
}

# Log an error and exit.
# Args:
# $1 Message to log with the error
# $2 The error code to return
# $3 The number of stack frames to skip when printing.
kube::log::error_exit() {
local message="${1:-}"
local code="${2:-1}"
local stack_skip="${3:-0}"
stack_skip=$((stack_skip + 1))

if [[ ${KUBE_VERBOSE} -ge 4 ]]; then
local source_file=${BASH_SOURCE[$stack_skip]}
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
echo "!!! Error in ${source_file}:${source_line}" >&2
[[ -z ${1-} ]] || {
echo " ${1}" >&2
}

kube::log::stack $stack_skip

echo "Exiting with status ${code}" >&2
fi

exit "${code}"
}

# Log an error but keep going. Don't dump the stack or exit.
kube::log::error() {
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "!!! $timestamp ${1-}" >&2
shift
for message; do
echo " $message" >&2
done
}

# Print an usage message to stderr. The arguments are printed directly.
kube::log::usage() {
echo >&2
local message
for message; do
echo "$message" >&2
done
echo >&2
}

kube::log::usage_from_stdin() {
local messages=()
while read -r line; do
messages+=("$line")
done

kube::log::usage "${messages[@]}"
}

# Print out some info that isn't a top level status line
kube::log::info() {
local V="${V:-0}"
if [[ $KUBE_VERBOSE < $V ]]; then
return
fi

for message; do
echo "$message"
done
}

# Just like kube::log::info, but no \n, so you can make a progress bar
kube::log::progress() {
for message; do
echo -e -n "$message"
done
}

kube::log::info_from_stdin() {
local messages=()
while read -r line; do
messages+=("$line")
done

kube::log::info "${messages[@]}"
}

# Print a status line. Formatted to show up in a stream of output.
kube::log::status() {
local V="${V:-0}"
if [[ $KUBE_VERBOSE < $V ]]; then
return
fi

timestamp=$(date +"[%m%d %H:%M:%S]")
echo "+++ $timestamp $1"
shift
for message; do
echo " $message"
done
}
64 changes: 17 additions & 47 deletions config/crds/batch_v1alpha1_job.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: jobs.batch.hpw.cloud
spec:
group: batch.hpw.cloud
Expand Down Expand Up @@ -104,7 +101,7 @@ spec:
type: string
event:
description: The Event recorded by scheduler; the controller takes
actions according to this Event. One of "PodFailed", "Unschedulable".
actions according to this Event.
type: string
timeout:
description: Timeout is the grace period for controller to take
Expand Down Expand Up @@ -133,8 +130,7 @@ spec:
type: string
event:
description: The Event recorded by scheduler; the controller
takes actions according to this Event. One of "PodFailed",
"Unschedulable".
takes actions according to this Event.
type: string
timeout:
description: Timeout is the grace period for controller
Expand All @@ -161,40 +157,6 @@ spec:
description: The number of pods which reached phase Succeeded.
format: int32
type: integer
conditions:
description: 'Current service state of pod. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-conditions
+patchMergeKey=type +patchStrategy=merge'
items:
properties:
lastProbeTime:
description: Last time we probed the condition.
format: date-time
type: string
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
format: date-time
type: string
message:
description: Human-readable message indicating details about last
transition.
type: string
reason:
description: Unique, one-word, CamelCase reason for the condition's
last transition.
type: string
status:
description: Status is the status of the condition. Can be True,
False, Unknown.
type: string
type:
description: Type is the type of the condition.
type: string
required:
- type
- status
type: object
type: array
failed:
description: The number of pods which reached phase Failed.
format: int32
Expand All @@ -207,17 +169,25 @@ spec:
description: The number of pending pods.
format: int32
type: integer
phase:
description: 'The phase of a Pod is a simple, high-level summary of
where the Pod is in its lifecycle. The conditions array, the reason
and message fields, and the individual container status arrays contain
more detail about the pod''s status. There are five possible phase
values:'
type: string
running:
description: The number of running pods.
format: int32
type: integer
state:
description: Current state of Job.
properties:
message:
description: Human-readable message indicating details about last
transition.
type: string
phase:
description: The phase of Job
type: string
reason:
description: Unique, one-word, CamelCase reason for the condition's
last transition.
type: string
type: object
type: object
version: v1alpha1
status:
Expand Down
44 changes: 44 additions & 0 deletions config/crds/bus_v1alpha1_command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: commands.bus.hpw.cloud
spec:
group: bus.hpw.cloud
names:
kind: Command
plural: commands
scope: Namespaced
validation:
openAPIV3Schema:
properties:
action:
description: Action defines the action that will be took to the target object.
type: string
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
message:
description: Human-readable message indicating details of this command.
type: string
metadata:
type: object
reason:
description: Unique, one-word, CamelCase reason for this command.
type: string
target:
description: TargetObject defines the target object of this command.
type: object
version: v1alpha1
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit 24ef641

Please sign in to comment.