Skip to content

Commit

Permalink
Merge pull request kubernetes#1480 from thockin/caps
Browse files Browse the repository at this point in the history
Capitalize string constants
  • Loading branch information
bgrant0607 committed Sep 28, 2014
2 parents cf26628 + f2cf958 commit 09a3231
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 155 deletions.
8 changes: 5 additions & 3 deletions cmd/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ func main() {
float32(*registryPullQPS),
*registryBurst)

health.AddHealthChecker("exec", health.NewExecHealthChecker(k))
health.AddHealthChecker("http", health.NewHTTPHealthChecker(&http.Client{}))
health.AddHealthChecker("tcp", &health.TCPHealthChecker{})
// TODO: These should probably become more plugin-ish: register a factory func
// in each checker's init(), iterate those here.
health.AddHealthChecker(health.NewExecHealthChecker(k))
health.AddHealthChecker(health.NewHTTPHealthChecker(&http.Client{}))
health.AddHealthChecker(&health.TCPHealthChecker{})

// start the kubelet
go util.Forever(func() { k.Run(cfg.Updates()) }, 0)
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ import (
func TestErrorNew(t *testing.T) {
err := NewAlreadyExists("test", "1")
if !IsAlreadyExists(err) {
t.Errorf("expected to be already_exists")
t.Errorf("expected to be %s", api.StatusReasonAlreadyExists)
}
if IsConflict(err) {
t.Errorf("expected to not be confict")
t.Errorf("expected to not be %s", api.StatusReasonConflict)
}
if IsNotFound(err) {
t.Errorf(fmt.Sprintf("expected to not be %s", api.StatusReasonNotFound))
}
if IsInvalid(err) {
t.Errorf("expected to not be invalid")
t.Errorf("expected to not be %s", api.StatusReasonInvalid)
}

if !IsConflict(NewConflict("test", "2", errors.New("message"))) {
t.Errorf("expected to be conflict")
}
if !IsNotFound(NewNotFound("test", "3")) {
t.Errorf("expected to be not found")
t.Errorf("expected to be %s", api.StatusReasonNotFound)
}
if !IsInvalid(NewInvalid("test", "2", nil)) {
t.Errorf("expected to be invalid")
t.Errorf("expected to be %s", api.StatusReasonInvalid)
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ func TestNewInvalid(t *testing.T) {
t.Errorf("%d: unexpected status: %#v", i, status)
}
if !reflect.DeepEqual(expected, status.Details) {
t.Errorf("%d: expected %#v, got %#v", expected, status.Details)
t.Errorf("%d: expected %#v, got %#v", i, expected, status.Details)
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/errors/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ import (
// CauseType in api/types.go.
type ValidationErrorType string

// TODO: These values are duplicated in api/types.go, but there's a circular dep. Fix it.
const (
// ValidationErrorTypeNotFound is used to report failure to find a requested value
// (e.g. looking up an ID).
ValidationErrorTypeNotFound ValidationErrorType = "fieldValueNotFound"
ValidationErrorTypeNotFound ValidationErrorType = "FieldValueNotFound"
// ValidationErrorTypeRequired is used to report required values that are not
// provided (e.g. empty strings, null values, or empty arrays).
ValidationErrorTypeRequired ValidationErrorType = "fieldValueRequired"
ValidationErrorTypeRequired ValidationErrorType = "FieldValueRequired"
// ValidationErrorTypeDuplicate is used to report collisions of values that must be
// unique (e.g. unique IDs).
ValidationErrorTypeDuplicate ValidationErrorType = "fieldValueDuplicate"
ValidationErrorTypeDuplicate ValidationErrorType = "FieldValueDuplicate"
// ValidationErrorTypeInvalid is used to report malformed values (e.g. failed regex
// match).
ValidationErrorTypeInvalid ValidationErrorType = "fieldValueInvalid"
ValidationErrorTypeInvalid ValidationErrorType = "FieldValueInvalid"
// ValidationErrorTypeNotSupported is used to report valid (as per formatting rules)
// values that can not be handled (e.g. an enumerated string).
ValidationErrorTypeNotSupported ValidationErrorType = "fieldValueNotSupported"
ValidationErrorTypeNotSupported ValidationErrorType = "FieldValueNotSupported"
)

func ValueOf(t ValidationErrorType) string {
Expand Down
52 changes: 30 additions & 22 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ type HostDirectory struct {

type EmptyDirectory struct{}

// Protocol defines network protocols supported for things like conatiner ports.
type Protocol string

const (
// ProtocolTCP is the TCP protocol.
ProtocolTCP Protocol = "TCP"
// ProtocolUDP is the UDP protocol.
ProtocolUDP Protocol = "UDP"
)

// Port represents a network port in a single container.
type Port struct {
// Optional: If specified, this must be a DNS_LABEL. Each named port
Expand All @@ -109,8 +119,8 @@ type Port struct {
HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
// Required: This must be a valid port number, 0 < x < 65536.
ContainerPort int `yaml:"containerPort" json:"containerPort"`
// Optional: Supports "TCP" and "UDP". Defaults to "TCP".
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
// Optional: Defaults to "TCP".
Protocol Protocol `yaml:"protocol,omitempty" json:"protocol,omitempty"`
// Optional: What host IP to bind the external port to.
HostIP string `yaml:"hostIP,omitempty" json:"hostIP,omitempty"`
}
Expand Down Expand Up @@ -161,8 +171,6 @@ type ExecAction struct {
// LivenessProbe describes a liveness probe to be examined to the container.
// TODO: pass structured data to the actions, and document that data here.
type LivenessProbe struct {
// Type of liveness probe. Current legal values "http", "tcp"
Type string `yaml:"type,omitempty" json:"type,omitempty"`
// HTTPGetProbe parameters, required if Type == 'http'
HTTPGet *HTTPGetAction `yaml:"httpGet,omitempty" json:"httpGet,omitempty"`
// TCPSocketProbe parameter, required if Type == 'tcp'
Expand Down Expand Up @@ -381,8 +389,8 @@ type Service struct {

// Required.
Port int `json:"port" yaml:"port"`
// Optional: Supports "TCP" and "UDP". Defaults to "TCP".
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
// Optional: Defaults to "TCP".
Protocol Protocol `yaml:"protocol,omitempty" json:"protocol,omitempty"`

// This service's labels.
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Expand Down Expand Up @@ -447,12 +455,12 @@ func (*Binding) IsAnAPIObject() {}
// import both.
type Status struct {
JSONBase `json:",inline" yaml:",inline"`
// One of: "success", "failure", "working" (for operations not yet completed)
// One of: "Success", "Failure", "Working" (for operations not yet completed)
Status string `json:"status,omitempty" yaml:"status,omitempty"`
// A human-readable description of the status of this operation.
Message string `json:"message,omitempty" yaml:"message,omitempty"`
// A machine-readable description of why this operation is in the
// "failure" or "working" status. If this value is empty there
// "Failure" or "Working" status. If this value is empty there
// is no information available. A Reason clarifies an HTTP status
// code but does not override it.
Reason StatusReason `json:"reason,omitempty" yaml:"reason,omitempty"`
Expand Down Expand Up @@ -487,9 +495,9 @@ type StatusDetails struct {

// Values of Status.Status
const (
StatusSuccess = "success"
StatusFailure = "failure"
StatusWorking = "working"
StatusSuccess = "Success"
StatusFailure = "Failure"
StatusWorking = "Working"
)

// StatusReason is an enumeration of possible failure causes. Each StatusReason
Expand All @@ -514,7 +522,7 @@ const (
// "Location" - HTTP header populated with a URL that can retrieved the final
// status of this operation.
// Status code 202
StatusReasonWorking StatusReason = "working"
StatusReasonWorking StatusReason = "Working"

// StatusReasonNotFound means one or more resources required for this operation
// could not be found.
Expand All @@ -524,21 +532,21 @@ const (
// resource.
// "id" string - the identifier of the missing resource
// Status code 404
StatusReasonNotFound StatusReason = "not_found"
StatusReasonNotFound StatusReason = "NotFound"

// StatusReasonAlreadyExists means the resource you are creating already exists.
// Details (optional):
// "kind" string - the kind attribute of the conflicting resource
// "id" string - the identifier of the conflicting resource
// Status code 409
StatusReasonAlreadyExists StatusReason = "already_exists"
StatusReasonAlreadyExists StatusReason = "AlreadyExists"

// StatusReasonConflict means the requested update operation cannot be completed
// due to a conflict in the operation. The client may need to alter the request.
// Each resource may define custom details that indicate the nature of the
// conflict.
// Status code 409
StatusReasonConflict StatusReason = "conflict"
StatusReasonConflict StatusReason = "Conflict"

// StatusReasonInvalid means the requested create or update operation cannot be
// completed due to invalid data provided as part of the request. The client may
Expand All @@ -551,7 +559,7 @@ const (
// provided resource that was invalid. The code, message, and
// field attributes will be set.
// Status code 422
StatusReasonInvalid StatusReason = "invalid"
StatusReasonInvalid StatusReason = "Invalid"
)

// StatusCause provides more information about an api.Status failure, including
Expand All @@ -577,25 +585,25 @@ type StatusCause struct {

// CauseType is a machine readable value providing more detail about what
// occured in a status response. An operation may have multiple causes for a
// status (whether failure, success, or working).
// status (whether Failure, Success, or Working).
type CauseType string

const (
// CauseTypeFieldValueNotFound is used to report failure to find a requested value
// (e.g. looking up an ID).
CauseTypeFieldValueNotFound CauseType = "fieldValueNotFound"
CauseTypeFieldValueNotFound CauseType = "FieldValueNotFound"
// CauseTypeFieldValueInvalid is used to report required values that are not
// provided (e.g. empty strings, null values, or empty arrays).
CauseTypeFieldValueRequired CauseType = "fieldValueRequired"
CauseTypeFieldValueRequired CauseType = "FieldValueRequired"
// CauseTypeFieldValueDuplicate is used to report collisions of values that must be
// unique (e.g. unique IDs).
CauseTypeFieldValueDuplicate CauseType = "fieldValueDuplicate"
CauseTypeFieldValueDuplicate CauseType = "FieldValueDuplicate"
// CauseTypeFieldValueInvalid is used to report malformed values (e.g. failed regex
// match).
CauseTypeFieldValueInvalid CauseType = "fieldValueInvalid"
CauseTypeFieldValueInvalid CauseType = "FieldValueInvalid"
// CauseTypeFieldValueNotSupported is used to report valid (as per formatting rules)
// values that can not be handled (e.g. an enumerated string).
CauseTypeFieldValueNotSupported CauseType = "fieldValueNotSupported"
CauseTypeFieldValueNotSupported CauseType = "FieldValueNotSupported"
)

// ServerOp is an operation delivered to API clients.
Expand Down
50 changes: 29 additions & 21 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ type HostDirectory struct {

type EmptyDirectory struct{}

// Protocol defines network protocols supported for things like conatiner ports.
type Protocol string

const (
// ProtocolTCP is the TCP protocol.
ProtocolTCP Protocol = "TCP"
// ProtocolUDP is the UDP protocol.
ProtocolUDP Protocol = "UDP"
)

// Port represents a network port in a single container.
type Port struct {
// Optional: If specified, this must be a DNS_LABEL. Each named port
Expand All @@ -109,8 +119,8 @@ type Port struct {
HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"`
// Required: This must be a valid port number, 0 < x < 65536.
ContainerPort int `yaml:"containerPort" json:"containerPort"`
// Optional: Supports "TCP" and "UDP". Defaults to "TCP".
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
// Optional: Defaults to "TCP".
Protocol Protocol `yaml:"protocol,omitempty" json:"protocol,omitempty"`
// Optional: What host IP to bind the external port to.
HostIP string `yaml:"hostIP,omitempty" json:"hostIP,omitempty"`
}
Expand Down Expand Up @@ -171,8 +181,6 @@ type ExecAction struct {
// LivenessProbe describes a liveness probe to be examined to the container.
// TODO: pass structured data to the actions, and document that data here.
type LivenessProbe struct {
// Type of liveness probe. Current legal values "http", "tcp"
Type string `yaml:"type,omitempty" json:"type,omitempty"`
// HTTPGetProbe parameters, required if Type == 'http'
HTTPGet *HTTPGetAction `yaml:"httpGet,omitempty" json:"httpGet,omitempty"`
// TCPSocketProbe parameter, required if Type == 'tcp'
Expand Down Expand Up @@ -394,8 +402,8 @@ type Service struct {

// Required.
Port int `json:"port" yaml:"port"`
// Optional: Supports "TCP" and "UDP". Defaults to "TCP".
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
// Optional: Defaults to "TCP".
Protocol Protocol `yaml:"protocol,omitempty" json:"protocol,omitempty"`

// This service's labels.
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Expand Down Expand Up @@ -463,12 +471,12 @@ func (*Binding) IsAnAPIObject() {}
// import both.
type Status struct {
JSONBase `json:",inline" yaml:",inline"`
// One of: "success", "failure", "working" (for operations not yet completed)
// One of: "Success", "Failure", "Working" (for operations not yet completed)
Status string `json:"status,omitempty" yaml:"status,omitempty"`
// A human-readable description of the status of this operation.
Message string `json:"message,omitempty" yaml:"message,omitempty"`
// A machine-readable description of why this operation is in the
// "failure" or "working" status. If this value is empty there
// "Failure" or "Working" status. If this value is empty there
// is no information available. A Reason clarifies an HTTP status
// code but does not override it.
Reason StatusReason `json:"reason,omitempty" yaml:"reason,omitempty"`
Expand Down Expand Up @@ -503,9 +511,9 @@ type StatusDetails struct {

// Values of Status.Status
const (
StatusSuccess = "success"
StatusFailure = "failure"
StatusWorking = "working"
StatusSuccess = "Success"
StatusFailure = "Failure"
StatusWorking = "Working"
)

// StatusReason is an enumeration of possible failure causes. Each StatusReason
Expand All @@ -530,7 +538,7 @@ const (
// "Location" - HTTP header populated with a URL that can retrieved the final
// status of this operation.
// Status code 202
StatusReasonWorking StatusReason = "working"
StatusReasonWorking StatusReason = "Working"

// StatusReasonNotFound means one or more resources required for this operation
// could not be found.
Expand All @@ -540,21 +548,21 @@ const (
// resource.
// "id" string - the identifier of the missing resource
// Status code 404
StatusReasonNotFound StatusReason = "notFound"
StatusReasonNotFound StatusReason = "NotFound"

// StatusReasonAlreadyExists means the resource you are creating already exists.
// Details (optional):
// "kind" string - the kind attribute of the conflicting resource
// "id" string - the identifier of the conflicting resource
// Status code 409
StatusReasonAlreadyExists StatusReason = "alreadyExists"
StatusReasonAlreadyExists StatusReason = "AlreadyExists"

// StatusReasonConflict means the requested update operation cannot be completed
// due to a conflict in the operation. The client may need to alter the request.
// Each resource may define custom details that indicate the nature of the
// conflict.
// Status code 409
StatusReasonConflict StatusReason = "conflict"
StatusReasonConflict StatusReason = "Conflict"
)

// StatusCause provides more information about an api.Status failure, including
Expand All @@ -580,25 +588,25 @@ type StatusCause struct {

// CauseType is a machine readable value providing more detail about what
// occured in a status response. An operation may have multiple causes for a
// status (whether failure, success, or working).
// status (whether Failure, Success, or Working).
type CauseType string

const (
// CauseTypeFieldValueNotFound is used to report failure to find a requested value
// (e.g. looking up an ID).
CauseTypeFieldValueNotFound CauseType = "fieldValueNotFound"
CauseTypeFieldValueNotFound CauseType = "FieldValueNotFound"
// CauseTypeFieldValueInvalid is used to report required values that are not
// provided (e.g. empty strings, null values, or empty arrays).
CauseTypeFieldValueRequired CauseType = "fieldValueRequired"
CauseTypeFieldValueRequired CauseType = "FieldValueRequired"
// CauseTypeFieldValueDuplicate is used to report collisions of values that must be
// unique (e.g. unique IDs).
CauseTypeFieldValueDuplicate CauseType = "fieldValueDuplicate"
CauseTypeFieldValueDuplicate CauseType = "FieldValueDuplicate"
// CauseTypeFieldValueInvalid is used to report malformed values (e.g. failed regex
// match).
CauseTypeFieldValueInvalid CauseType = "fieldValueInvalid"
CauseTypeFieldValueInvalid CauseType = "FieldValueInvalid"
// CauseTypeFieldValueNotSupported is used to report valid (as per formatting rules)
// values that can not be handled (e.g. an enumerated string).
CauseTypeFieldValueNotSupported CauseType = "fieldValueNotSupported"
CauseTypeFieldValueNotSupported CauseType = "FieldValueNotSupported"
)

// ServerOp is an operation delivered to API clients.
Expand Down
Loading

0 comments on commit 09a3231

Please sign in to comment.