Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditions to camel-k CRs #766

Merged
merged 2 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions pkg/apis/camel/v1alpha1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -42,16 +43,17 @@ type BuildSpec struct {

// BuildStatus defines the observed state of Build
type BuildStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
Phase BuildPhase `json:"phase,omitempty"`
Image string `json:"image,omitempty"`
BaseImage string `json:"baseImage,omitempty"`
PublicImage string `json:"publicImage,omitempty"`
Artifacts []Artifact `json:"artifacts,omitempty"`
Error string `json:"error,omitempty"`
Failure *Failure `json:"failure,omitempty"`
StartedAt metav1.Time `json:"startedAt,omitempty"`
Phase BuildPhase `json:"phase,omitempty"`
Image string `json:"image,omitempty"`
BaseImage string `json:"baseImage,omitempty"`
PublicImage string `json:"publicImage,omitempty"`
Artifacts []Artifact `json:"artifacts,omitempty"`
Error string `json:"error,omitempty"`
Failure *Failure `json:"failure,omitempty"`
StartedAt metav1.Time `json:"startedAt,omitempty"`
Platform string `json:"platform,omitempty"`
Conditions []BuildCondition `json:"conditions,omitempty"`

// Change to Duration / ISO 8601 when CRD uses OpenAPI spec v3
// https://github.com/OAI/OpenAPI-Specification/issues/845
Duration string `json:"duration,omitempty"`
Expand All @@ -60,6 +62,9 @@ type BuildStatus struct {
// BuildPhase --
type BuildPhase string

// BuildConditionType --
type BuildConditionType string

const (
// BuildKind --
BuildKind string = "Build"
Expand All @@ -84,6 +89,11 @@ const (
BuildPhaseInterrupted = "Interrupted"
// BuildPhaseError --
BuildPhaseError BuildPhase = "Error"

// BuildConditionPlatformAvailable --
BuildConditionPlatformAvailable BuildConditionType = "IntegrationPlatformAvailable"
// BuildConditionPlatformAvailableReason --
BuildConditionPlatformAvailableReason string = "IntegrationPlatformAvailable"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -107,6 +117,22 @@ type BuildList struct {
Items []Build `json:"items"`
}

// Condition describes the state of a resource at a certain point.
type BuildCondition struct {
// Type of integration condition.
Type BuildConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// The last time this condition was updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
}

func init() {
SchemeBuilder.Register(&Build{}, &BuildList{})
}
92 changes: 91 additions & 1 deletion pkg/apis/camel/v1alpha1/build_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.

package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NewBuild --
func NewBuild(namespace string, name string) Build {
Expand All @@ -42,3 +45,90 @@ func NewBuildList() BuildList {
},
}
}

// SetIntegrationPlatform --
func (in *Build) SetIntegrationPlatform(platform *IntegrationPlatform) {
cs := corev1.ConditionTrue

if platform.Status.Phase != IntegrationPlatformPhaseReady {
cs = corev1.ConditionFalse
}

in.Status.SetCondition(BuildConditionPlatformAvailable, cs, BuildConditionPlatformAvailableReason, platform.Name)
in.Status.Platform = platform.Name
}

// GetCondition returns the condition with the provided type.
func (in *BuildStatus) GetCondition(condType BuildConditionType) *BuildCondition {
for i := range in.Conditions {
c := in.Conditions[i]
if c.Type == condType {
return &c
}
}
return nil
}

// SetCondition --
func (in *BuildStatus) SetCondition(condType BuildConditionType, status corev1.ConditionStatus, reason string, message string) {
in.SetConditions(BuildCondition{
Type: condType,
Status: status,
LastUpdateTime: metav1.Now(),
LastTransitionTime: metav1.Now(),
Reason: reason,
Message: message,
})
}

// SetErrorCondition --
func (in *BuildStatus) SetErrorCondition(condType BuildConditionType, reason string, err error) {
in.SetConditions(BuildCondition{
Type: condType,
Status: corev1.ConditionFalse,
LastUpdateTime: metav1.Now(),
LastTransitionTime: metav1.Now(),
Reason: reason,
Message: err.Error(),
})
}

// SetConditions updates the resource to include the provided conditions.
//
// If a condition that we are about to add already exists and has the same status and
// reason then we are not going to update.
func (in *BuildStatus) SetConditions(conditions ...BuildCondition) {
for _, condition := range conditions {
if condition.LastUpdateTime.IsZero() {
condition.LastUpdateTime = metav1.Now()
}
if condition.LastTransitionTime.IsZero() {
condition.LastTransitionTime = metav1.Now()
}

currentCond := in.GetCondition(condition.Type)

if currentCond != nil && currentCond.Status == condition.Status && currentCond.Reason == condition.Reason {
return
}
// Do not update lastTransitionTime if the status of the condition doesn't change.
if currentCond != nil && currentCond.Status == condition.Status {
condition.LastTransitionTime = currentCond.LastTransitionTime
}

in.RemoveCondition(condition.Type)
in.Conditions = append(in.Conditions, condition)
}
}

// RemoveCondition removes the resource condition with the provided type.
func (in *BuildStatus) RemoveCondition(condType BuildConditionType) {
newConditions := in.Conditions[:0]
for _, c := range in.Conditions {
if c.Type != condType {
newConditions = append(newConditions, c)
}
}

in.Conditions = newConditions
}
10 changes: 10 additions & 0 deletions pkg/apis/camel/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type Configurable interface {
Configurations() []ConfigurationSpec
}

// PlatformInjectable --
type PlatformInjectable interface {
SetIntegrationPlatform(platform *IntegrationPlatform)
}

// MavenSpec --
type MavenSpec struct {
Settings ValueSource `json:"settings,omitempty"`
Expand All @@ -72,3 +77,8 @@ type ValueSource struct {
// Selects a key of a secret.
SecretKeyRef *corev1.SecretKeySelector `json:"secretKeyRef,omitempty" `
}

const (
// ServiceTypeUser --
ServiceTypeUser = "user"
)
82 changes: 71 additions & 11 deletions pkg/apis/camel/v1alpha1/integration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -39,17 +40,19 @@ type IntegrationSpec struct {

// IntegrationStatus defines the observed state of Integration
type IntegrationStatus struct {
Phase IntegrationPhase `json:"phase,omitempty"`
Digest string `json:"digest,omitempty"`
Image string `json:"image,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Kit string `json:"kit,omitempty"`
GeneratedSources []SourceSpec `json:"generatedSources,omitempty"`
Failure *Failure `json:"failure,omitempty"`
CamelVersion string `json:"camelVersion,omitempty"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
Version string `json:"version,omitempty"`
Phase IntegrationPhase `json:"phase,omitempty"`
Digest string `json:"digest,omitempty"`
Image string `json:"image,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Kit string `json:"kit,omitempty"`
Platform string `json:"platform,omitempty"`
GeneratedSources []SourceSpec `json:"generatedSources,omitempty"`
Failure *Failure `json:"failure,omitempty"`
CamelVersion string `json:"camelVersion,omitempty"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
Conditions []IntegrationCondition `json:"conditions,omitempty"`
Version string `json:"version,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -139,6 +142,9 @@ var Languages = []Language{
// IntegrationPhase --
type IntegrationPhase string

// IntegrationConditionType --
type IntegrationConditionType string

const (
// IntegrationKind --
IntegrationKind string = "Integration"
Expand All @@ -161,8 +167,62 @@ const (
IntegrationPhaseError IntegrationPhase = "Error"
// IntegrationPhaseDeleting --
IntegrationPhaseDeleting IntegrationPhase = "Deleting"

// IntegrationConditionKitAvailable --
IntegrationConditionKitAvailable IntegrationConditionType = "IntegrationKitAvailable"
// IntegrationConditionPlatformAvailable --
IntegrationConditionPlatformAvailable IntegrationConditionType = "IntegrationPlatformAvailable"
// IntegrationConditionDeploymentAvailable --
IntegrationConditionDeploymentAvailable IntegrationConditionType = "DeploymentAvailable"
// IntegrationConditionServiceAvailable --
IntegrationConditionServiceAvailable IntegrationConditionType = "ServiceAvailable"
// IntegrationConditionKnativeServiceAvailable --
IntegrationConditionKnativeServiceAvailable IntegrationConditionType = "KnativeServiceAvailable"
// IntegrationConditionExposureAvailable --
IntegrationConditionExposureAvailable IntegrationConditionType = "ExposureAvailable"

// IntegrationConditionKitAvailableReason --
IntegrationConditionKitAvailableReason string = "IntegrationKitAvailable"
// IntegrationConditionPlatformAvailableReason --
IntegrationConditionPlatformAvailableReason string = "IntegrationPlatformAvailable"
// IntegrationConditionDeploymentAvailableReason --
IntegrationConditionDeploymentAvailableReason string = "DeploymentAvailable"
// IntegrationConditionDeploymentNotAvailableReason --
IntegrationConditionDeploymentNotAvailableReason string = "DeploymentNotAvailable"
// IntegrationConditionServiceAvailableReason --
IntegrationConditionServiceAvailableReason string = "ServiceAvailable"
// IntegrationConditionServiceNotAvailableReason --
IntegrationConditionServiceNotAvailableReason string = "ServiceNotAvailable"
// IntegrationConditionRouteAvailableReason --
IntegrationConditionRouteAvailableReason string = "RouteAvailable"
// IntegrationConditionRouteNotAvailableReason --
IntegrationConditionRouteNotAvailableReason string = "RouteNotAvailable"
// IntegrationConditionIngressAvailableReason --
IntegrationConditionIngressAvailableReason string = "IngressAvailable"
// IntegrationConditionIngressNotAvailableReason --
IntegrationConditionIngressNotAvailableReason string = "IngressNotAvailable"
// IntegrationConditionKnativeServiceAvailableReason --
IntegrationConditionKnativeServiceAvailableReason string = "KnativeServiceAvailable"
// IntegrationConditionKnativeServiceNotAvailableReason --
IntegrationConditionKnativeServiceNotAvailableReason string = "KnativeServiceNotAvailable"
)

// IntegrationCondition describes the state of a resource at a certain point.
type IntegrationCondition struct {
// Type of integration condition.
Type IntegrationConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// The last time this condition was updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
}

func init() {
SchemeBuilder.Register(&Integration{}, &IntegrationList{})
}
Loading