-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controller): reconcileV2 function skeleton
- Loading branch information
1 parent
7a62cc6
commit 4cddea4
Showing
24 changed files
with
667 additions
and
4,958 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package v2alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// UpdateDatadogAgentStatusConditionsFailure used to update the failure StatusConditions | ||
func UpdateDatadogAgentStatusConditionsFailure(status *DatadogAgentStatus, now metav1.Time, conditionType string, err error) { | ||
if err != nil { | ||
UpdateDatadogAgentStatusConditions(status, now, conditionType, metav1.ConditionTrue, fmt.Sprintf("%v", err), false) | ||
} else { | ||
UpdateDatadogAgentStatusConditions(status, now, conditionType, metav1.ConditionFalse, "", false) | ||
} | ||
} | ||
|
||
// UpdateDatadogAgentStatusConditions used to update a specific string in conditions | ||
func UpdateDatadogAgentStatusConditions(status *DatadogAgentStatus, now metav1.Time, t string, conditionStatus metav1.ConditionStatus, desc string, writeFalseIfNotExist bool) { | ||
idConditionComplete := getIndexForConditionType(status, t) | ||
if idConditionComplete >= 0 { | ||
UpdateDatadogAgentStatusCondition(status.Conditions[idConditionComplete], now, t, conditionStatus, desc) | ||
} else if conditionStatus == metav1.ConditionTrue || writeFalseIfNotExist { | ||
// Only add if the condition is True | ||
status.Conditions = append(status.Conditions, NewDatadogAgentStatusCondition(t, conditionStatus, now, "", desc)) | ||
} | ||
} | ||
|
||
// UpdateDatadogAgentStatusCondition used to update a specific string | ||
func UpdateDatadogAgentStatusCondition(condition metav1.Condition, now metav1.Time, t string, conditionStatus metav1.ConditionStatus, desc string) metav1.Condition { | ||
if condition.Status != conditionStatus { | ||
condition.LastTransitionTime = now | ||
condition.Status = conditionStatus | ||
} | ||
condition.LastTransitionTime = now | ||
condition.Message = desc | ||
|
||
return condition | ||
} | ||
|
||
// SetDatadogAgentStatusCondition use to set a condition | ||
func SetDatadogAgentStatusCondition(status *DatadogAgentStatus, condition *metav1.Condition) { | ||
idConditionComplete := getIndexForConditionType(status, condition.Type) | ||
if idConditionComplete >= 0 { | ||
status.Conditions[idConditionComplete] = *condition | ||
} else { | ||
status.Conditions = append(status.Conditions, *condition) | ||
} | ||
} | ||
|
||
// NewDatadogAgentStatusCondition returns new DatadogAgentCondition instance | ||
func NewDatadogAgentStatusCondition(conditionType string, conditionStatus metav1.ConditionStatus, now metav1.Time, reason, message string) metav1.Condition { | ||
return metav1.Condition{ | ||
Type: conditionType, | ||
Status: conditionStatus, | ||
LastTransitionTime: now, | ||
Reason: reason, | ||
Message: message, | ||
} | ||
} | ||
|
||
func getIndexForConditionType(status *DatadogAgentStatus, t string) int { | ||
idCondition := -1 | ||
if status == nil { | ||
return idCondition | ||
} | ||
|
||
for i, condition := range status.Conditions { | ||
if condition.Type == t { | ||
idCondition = i | ||
break | ||
} | ||
} | ||
|
||
return idCondition | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package v2alpha1 | ||
|
||
const ( | ||
|
||
// ClusterAgentReconcileConditionType ReconcileConditionType for Cluster Agent component | ||
ClusterAgentReconcileConditionType = "ClusterAgentReconcile" | ||
// AgentReconcileConditionType ReconcileConditionType for Agent component | ||
AgentReconcileConditionType = "AgentReconcile" | ||
// ClusterCheckRunnerReconcileConditionType ReconcileConditionType for Cluster Check Runner component | ||
ClusterCheckRunnerReconcileConditionType = "ClusterCheckRunnerReconcile" | ||
// DatadogAgentReconcileErrorConditionType ReconcileConditionType for DatadogAgent reconcile error | ||
DatadogAgentReconcileErrorConditionType = "DatadogAgentReconcileError" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.