Skip to content

Commit

Permalink
fix KHState CRD time field by making it nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnydawg committed Jul 30, 2021
1 parent ef94f91 commit 23c22cf
Show file tree
Hide file tree
Showing 20 changed files with 5,263 additions and 890 deletions.
3 changes: 2 additions & 1 deletion cmd/kuberhealthy/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func setCheckStateResource(checkName string, checkNamespace string, state khstat

// set the pod name that wrote the khstate
state.AuthoritativePod = podHostname
state.LastRun = metav1.Now() // set the time the khstate was last
now := metav1.Now() // set the time the khstate was last
state.LastRun = &now

khState := khstatev1.NewKuberhealthyState(name, state)
khState.SetResourceVersion(resourceVersion)
Expand Down
527 changes: 458 additions & 69 deletions deploy/helm/kuberhealthy/crds/comcast.github.io_khchecks.yaml

Large diffs are not rendered by default.

527 changes: 458 additions & 69 deletions deploy/helm/kuberhealthy/crds/comcast.github.io_khjobs.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: khstates.comcast.github.io
spec:
Expand Down Expand Up @@ -61,6 +61,7 @@ spec:
type: array
LastRun:
format: date-time
nullable: true
type: string
Namespace:
type: string
Expand All @@ -70,6 +71,11 @@ spec:
type: boolean
RunDuration:
type: string
khWorkload:
description: 'KHWorkload is used to describe the different types of
kuberhealthy workloads: KhCheck or KHJob'
nullable: true
type: string
uuid:
type: string
required:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
{{- if .Values.podDisruptionBudget.enabled }}
apiVersion: policy/v1beta1
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ template "kuberhealthy.name" . }}-pdb
Expand Down
1,214 changes: 999 additions & 215 deletions deploy/kuberhealthy-prometheus-operator.yaml

Large diffs are not rendered by default.

1,128 changes: 956 additions & 172 deletions deploy/kuberhealthy-prometheus.yaml

Large diffs are not rendered by default.

1,128 changes: 956 additions & 172 deletions deploy/kuberhealthy.yaml

Large diffs are not rendered by default.

31 changes: 25 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,48 @@ module github.com/kuberhealthy/kuberhealthy/v2

require (
github.com/Pallinder/go-randomdata v1.1.0
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/aws/aws-sdk-go v1.25.24
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/brancz/gojsontoyaml v0.0.0-20210709073738-09985366e724 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/codingsince1985/checksum v1.1.0
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/denverdino/aliyungo v0.0.0-20191023002520-dba750c0c223 // indirect
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0 // indirect
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-ini/ini v1.49.0 // indirect
github.com/go-openapi/validate v0.19.5 // indirect
github.com/gobuffalo/flect v0.2.3 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/uuid v1.1.2
github.com/gophercloud/gophercloud v0.1.0 // indirect
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75
github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc
github.com/integrii/flaggy v1.2.2
github.com/onsi/gomega v1.14.0 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.10.1 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/sirupsen/logrus v1.7.0
github.com/smartystreets/goconvey v1.6.4 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
github.com/spf13/cobra v1.2.1 // indirect
github.com/ugorji/go v1.1.4 // indirect
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
golang.org/x/tools v0.1.5 // indirect
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.19.3
k8s.io/apimachinery v0.19.3
k8s.io/client-go v0.19.0
gotest.tools v2.2.0+incompatible // indirect
k8s.io/api v0.21.3
k8s.io/apiextensions-apiserver v0.21.3 // indirect
k8s.io/apimachinery v0.21.3
k8s.io/client-go v0.21.3
k8s.io/klog v1.0.0 // indirect
k8s.io/kops v1.11.0
sigs.k8s.io/controller-tools v0.4.1 // indirect
sigs.k8s.io/controller-tools v0.6.2 // indirect
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 // indirect
)

go 1.15
421 changes: 421 additions & 0 deletions go.sum

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions pkg/apis/khcheck/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
// +kubebuilder:resource:singular="khcheck"
// +kubebuilder:resource:shortName="khc"
type KuberhealthyCheck struct {
metav1.TypeMeta `json:",inline"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

// Spec holds the desired state of the KuberhealthyCheck (from the client).
// +optional
Spec CheckConfig `json:"spec,omitempty"`
Spec CheckConfig `json:"spec,omitempty" yaml:"spec,omitempty"`
}

// CheckConfig represents a configuration for a kuberhealthy external
Expand All @@ -30,21 +30,21 @@ type KuberhealthyCheck struct {
// endpoint.
// +k8s:openapi-gen=true
type CheckConfig struct {
RunInterval string `json:"runInterval"` // the interval at which the check runs
Timeout string `json:"timeout"` // the maximum time the pod is allowed to run before a failure is assumed
PodSpec apiv1.PodSpec `json:"podSpec"` // a spec for the external checker
RunInterval string `json:"runInterval" yaml:"runInterval"` // the interval at which the check runs
Timeout string `json:"timeout" yaml:"timeout"` // the maximum time the pod is allowed to run before a failure is assumed
PodSpec apiv1.PodSpec `json:"podSpec" yaml:"podSpec"` // a spec for the external checker
// +optional
ExtraAnnotations map[string]string `json:"extraAnnotations"` // a map of extra annotations that will be applied to the pod
ExtraAnnotations map[string]string `json:"extraAnnotations" yaml:"extraAnnotations"` // a map of extra annotations that will be applied to the pod
// +optional
ExtraLabels map[string]string `json:"extraLabels"` // a map of extra labels that will be applied to the pod
ExtraLabels map[string]string `json:"extraLabels" yaml:"extraLabels"` // a map of extra labels that will be applied to the pod
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// KuberhealthyCheckList is a list of KuberhealthyCheck resources
type KuberhealthyCheckList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata" yaml:"metadata"`

Items []KuberhealthyCheck `json:"items"`
Items []KuberhealthyCheck `json:"items" yaml:"items"`
}
22 changes: 11 additions & 11 deletions pkg/apis/khjob/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
// +kubebuilder:resource:singular="khjob"
// +kubebuilder:resource:shortName="khj"
type KuberhealthyJob struct {
metav1.TypeMeta `json:",inline"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

// Spec holds the desired state of the KuberhealthyJob (from the client).
// +optional
Spec JobConfig `json:"spec,omitempty"`
Spec JobConfig `json:"spec,omitempty" yaml:"spec,omitempty"`
}

// JobConfig represents a configuration for a kuberhealthy external
Expand All @@ -31,13 +31,13 @@ type KuberhealthyJob struct {
// +k8s:openapi-gen=true
type JobConfig struct {
// +optional
Phase JobPhase `json:"phase"` // the state or phase of the job
Timeout string `json:"timeout"` // the maximum time the pod is allowed to run before a failure is assumed
PodSpec apiv1.PodSpec `json:"podSpec"` // a spec for the external job
Phase JobPhase `json:"phase" yaml:"phase"` // the state or phase of the job
Timeout string `json:"timeout" yaml:"timeout"` // the maximum time the pod is allowed to run before a failure is assumed
PodSpec apiv1.PodSpec `json:"podSpec" yaml:"podSpec"` // a spec for the external job
// +optional
ExtraAnnotations map[string]string `json:"extraAnnotations"` // a map of extra annotations that will be applied to the pod
ExtraAnnotations map[string]string `json:"extraAnnotations" yaml:"extraAnnotations"` // a map of extra annotations that will be applied to the pod
// +optional
ExtraLabels map[string]string `json:"extraLabels"` // a map of extra labels that will be applied to the pod
ExtraLabels map[string]string `json:"extraLabels" yaml:"extraLabels"` // a map of extra labels that will be applied to the pod
}

// JobPhase is a label for the condition of the job at the current time.
Expand All @@ -53,8 +53,8 @@ const (

// KuberhealthyJobList is a list of KuberhealthyJob resources
type KuberhealthyJobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata" yaml:"metadata"`

Items []KuberhealthyJob `json:"items"`
Items []KuberhealthyJob `json:"items" yaml:"items"`
}
8 changes: 4 additions & 4 deletions pkg/apis/khstate/v1/khstatecrd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions pkg/apis/khstate/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,30 @@ import (
// +kubebuilder:resource:singular="khstate"
// +kubebuilder:resource:shortName="khs"
type KuberhealthyState struct {
metav1.TypeMeta `json:",inline"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

// Spec holds the desired state of the KuberhealthyState (from the client).
// +optional
Spec WorkloadDetails `json:"spec"`
Spec WorkloadDetails `json:"spec" yaml:"spec"`
}

// WorkloadDetails contains details about a single kuberhealthy check or job's current status
// +k8s:openapi-gen=true
// +nullable:name="LastRun"
type WorkloadDetails struct {
OK bool `json:"OK"` // true or false status of the khWorkload, whether or not it completed successfully
Errors []string `json:"Errors"` // the list of errors reported from the khWorkload run
RunDuration string `json:"RunDuration"` // the time it took for the khWorkload to complete
Namespace string `json:"Namespace"` // the namespace the khWorkload was run in
Node string `json:"Node"` // the node the khWorkload ran on
// +optional
LastRun metav1.Time `json:"LastRun"` // the time the khWorkload was last run
AuthoritativePod string `json:"AuthoritativePod"` // the main kuberhealthy pod creating and updating the khstate
CurrentUUID string `json:"uuid"` // the UUID that is authorized to report statuses into the kuberhealthy endpoint
khWorkload KHWorkload
OK bool `json:"OK" yaml:"OK"` // true or false status of the khWorkload, whether or not it completed successfully
Errors []string `json:"Errors" yaml:"Errors"` // the list of errors reported from the khWorkload run
RunDuration string `json:"RunDuration" yaml:"RunDuration"` // the time it took for the khWorkload to complete
Namespace string `json:"Namespace" yaml:"Namespace"` // the namespace the khWorkload was run in
Node string `json:"Node" yaml:"Node"` // the node the khWorkload ran on
// +nullable
LastRun *metav1.Time `json:"LastRun,omitempty" yaml:"LastRun,omitempty"` // the time the khWorkload was last run
AuthoritativePod string `json:"AuthoritativePod" yaml:"AuthoritativePod"` // the main kuberhealthy pod creating and updating the khstate
CurrentUUID string `json:"uuid" yaml:"uuid"` // the UUID that is authorized to report statuses into the kuberhealthy endpoint
// +nullable
khWorkload *KHWorkload `json:"khWorkload,omitempty" yaml:"khWorkload,omitempty"`
}

// KHWorkload is used to describe the different types of kuberhealthy workloads: KhCheck or KHJob
Expand All @@ -56,8 +58,8 @@ const (

// KuberhealthyStateList is a list of KuberhealthyState resources
type KuberhealthyStateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata" yaml:"metadata"`

Items []KuberhealthyState `json:"items"`
Items []KuberhealthyState `json:"items" yaml:"items"`
}
9 changes: 7 additions & 2 deletions pkg/checks/external/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type Checker struct {
KuberhealthyReportingURL string // the URL that the check should want to report results back to
ExtraAnnotations map[string]string
ExtraLabels map[string]string
Node string // the node the checker pod runs on
Node string // the node the checker pod runs on
currentCheckUUID string // the UUID of the current external checker running
Debug bool // indicates we should run in debug mode - run once and stop
shutdownCTXFunc context.CancelFunc // used to cancel things in-flight when shutting down gracefully
Expand Down Expand Up @@ -760,7 +760,12 @@ func (ext *Checker) getCheckLastUpdateTime() (metav1.Time, error) {
return metav1.Time{}, nil
}

return state.Spec.LastRun, err
// return a zero time if the time is nil / zero
if state.Spec.LastRun.IsZero() {
return metav1.Time{}, nil
}

return *state.Spec.LastRun, err
}

// waitForPodStatusUpdate waits for a pod status to update from the specified time
Expand Down
5 changes: 5 additions & 0 deletions scripts/generate-crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (generator crdGenerator) generateYAMLManifests() error {
"paths=.",
"output:crd:dir="+outputDir,
)

cmd.Dir, err = filepath.Abs(generator.ControllerPath)
if err != nil {
return errors.Wrapf(err, "absolute controller path %s", generator.ControllerPath)
Expand All @@ -105,14 +106,18 @@ func (generator crdGenerator) generateYAMLManifests() error {
if err != nil {
log.Fatalln(err)
}

cmdOutputErr, err := cmd.StderrPipe()
if err != nil {
log.Fatalln(err)
}

go io.Copy(os.Stdout, cmdOutput)
go io.Copy(os.Stderr, cmdOutputErr)

err = cmd.Run()
if err != nil {
log.Printf("failed to run command %v", err.Error())
return err
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2
go get github.com/brancz/gojsontoyaml

GOPATH=$(go env GOPATH)
Expand Down
Loading

0 comments on commit 23c22cf

Please sign in to comment.