Skip to content

Instantly share code, notes, and snippets.

@moosh3
Last active May 7, 2020 19:03
Show Gist options
  • Save moosh3/7b894c9c3fcd054d93e335921d1151f0 to your computer and use it in GitHub Desktop.
Save moosh3/7b894c9c3fcd054d93e335921d1151f0 to your computer and use it in GitHub Desktop.
/*
Copyright 2020 The Flux CD contributors.
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.
*/
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Condition contains condition information for a kustomization.
type Condition struct {
// Type of the condition, currently ('Ready').
// +required
Type string `json:"type"`
// Status of the condition, one of ('True', 'False', 'Unknown').
// +required
Status corev1.ConditionStatus `json:"status"`
// LastTransitionTime is the timestamp corresponding to the last status
// change of this condition.
// +required
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Reason is a brief machine readable explanation for the condition's last
// transition.
// +required
Reason string `json:"reason,omitempty"`
// Message is a human readable description of the details of the last
// transition, complementing reason.
// +optional
Message string `json:"message,omitempty"`
}
const (
// ReadyCondition represents the fact that a given kustomization has passed
// validation and was successfully applied on the cluster.
ReadyCondition string = "Ready"
)
const (
// ApplySucceedReason represents the fact that the kustomization apply succeed.
ApplySucceedReason string = "ApplySucceed"
// ApplyFailedReason represents the fact that the kustomization apply failed.
ApplyFailedReason string = "ApplyFailed"
// PruneFailedReason represents the fact that the kustomization pruning failed.
PruneFailedReason string = "PruneFailed"
// ArtifactFailedReason represents the fact that the artifact download failed.
ArtifactFailedReason string = "ArtifactFailed"
// BuildFailedReason represents the fact that the kustomize build command failed.
BuildFailedReason string = "BuildFailed"
// DependencyNotReady represents the fact that the one of the dependencies is not ready.
DependencyNotReadyReason string = "DependencyNotReady"
// HealthCheckFailedReason represents the fact that the one of the health check failed.
HealthCheckFailedReason string = "HealthCheckFailed"
// InitializedReason represents the fact that a given resource has been initialized.
InitializedReason string = "Initialized"
// ProgressingReason represents the fact that a kustomization reconciliation
// is underway.
ProgressingReason string = "Progressing"
// SuspendedReason represents the fact that the kustomization execution is suspended.
SuspendedReason string = "Suspended"
// ValidationFailedReason represents the fact that the dry-run apply failed.
ValidationFailedReason string = "ValidationFailed"
)
func (r *AppServiceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
ctx = context.Background()
log = r.Log.WithValues("appservice", req.NamespacedName)
var appService caretalks.AppService
if err := r.Get(ctx, req.NamespacedName, &appService); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
init := true
for _, condition := range appService.Status.Conditions {
if condition.Type == caretalks.ReadyConditions && condition.Status == corev1.ConditionTrue {
init = false
break
}
}
if init {
appService.Status.Conditions = []caretalks.Condition{
{
Type: caretalks.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: caretalks.InitializedReason,
Message: caretalks.InitializedReason,
},
}
if err := r.Status().Update(ctx, &appService); err != nil {
return ctrl.Result{Requeue: true}, err
}
log.Info("AppService initializaed")
}
return ctrl.Result{}, nil
// your logic here
return ctrl.Result{}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment