Skip to content

Commit

Permalink
deploy: aebfff6
Browse files Browse the repository at this point in the history
  • Loading branch information
aghilish committed May 14, 2024
1 parent b298d8c commit ebcf5a6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 32 deletions.
43 changes: 28 additions & 15 deletions print.html
Original file line number Diff line number Diff line change
Expand Up @@ -4121,24 +4121,37 @@ <h2 id="using-our-functions-in-the-reconcile-loop"><a class="header" href="#usin
</code></pre>
<p>and we add two helper functions to our controller. <code>internal/controller/ghost_controller.go</code></p>
<pre><code class="language-go">// Function to add a condition to the GhostStatus
func (s *GhostStatus) addCondition(condType metav1.ConditionType, status metav1.ConditionStatus, reason, message string) {
condition := metav1.Condition{
Type: condType,
Status: status,
Reason: reason,
Message: message,
}
s.Conditions = append(s.Conditions, condition)
func addCondition(status *blogv1.GhostStatus, condType string, statusType metav1.ConditionStatus, reason, message string) {
for i, existingCondition := range status.Conditions {
if existingCondition.Type == condType {
// Condition already exists, update it
status.Conditions[i].Status = statusType
status.Conditions[i].Reason = reason
status.Conditions[i].Message = message
status.Conditions[i].LastTransitionTime = metav1.Now()
return
}
}

// Condition does not exist, add it
condition := metav1.Condition{
Type: condType,
Status: statusType,
Reason: reason,
Message: message,
LastTransitionTime: metav1.Now(),
}
status.Conditions = append(status.Conditions, condition)
}

// Function to update the status of the Ghost object
func (r *GhostReconciler) updateStatus(ctx context.Context, ghost *blogv1.Ghost, status *blogv1.GhostStatus) error {
// Update the status of the Ghost object
ghost.Status = *status
if err := r.Status().Update(ctx, ghost); err != nil {
return err
}
return nil
func (r *GhostReconciler) updateStatus(ctx context.Context, ghost *blogv1.Ghost) error {
// Update the status of the Ghost object
if err := r.Status().Update(ctx, ghost); err != nil {
return err
}

return nil
}
</code></pre>
<p>And finally our reconcile function should be replaced with the following snippet.</p>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searchindex.json

Large diffs are not rendered by default.

43 changes: 28 additions & 15 deletions tutorials/extending-k8s.html
Original file line number Diff line number Diff line change
Expand Up @@ -841,24 +841,37 @@ <h2 id="using-our-functions-in-the-reconcile-loop"><a class="header" href="#usin
</code></pre>
<p>and we add two helper functions to our controller. <code>internal/controller/ghost_controller.go</code></p>
<pre><code class="language-go">// Function to add a condition to the GhostStatus
func (s *GhostStatus) addCondition(condType metav1.ConditionType, status metav1.ConditionStatus, reason, message string) {
condition := metav1.Condition{
Type: condType,
Status: status,
Reason: reason,
Message: message,
}
s.Conditions = append(s.Conditions, condition)
func addCondition(status *blogv1.GhostStatus, condType string, statusType metav1.ConditionStatus, reason, message string) {
for i, existingCondition := range status.Conditions {
if existingCondition.Type == condType {
// Condition already exists, update it
status.Conditions[i].Status = statusType
status.Conditions[i].Reason = reason
status.Conditions[i].Message = message
status.Conditions[i].LastTransitionTime = metav1.Now()
return
}
}

// Condition does not exist, add it
condition := metav1.Condition{
Type: condType,
Status: statusType,
Reason: reason,
Message: message,
LastTransitionTime: metav1.Now(),
}
status.Conditions = append(status.Conditions, condition)
}

// Function to update the status of the Ghost object
func (r *GhostReconciler) updateStatus(ctx context.Context, ghost *blogv1.Ghost, status *blogv1.GhostStatus) error {
// Update the status of the Ghost object
ghost.Status = *status
if err := r.Status().Update(ctx, ghost); err != nil {
return err
}
return nil
func (r *GhostReconciler) updateStatus(ctx context.Context, ghost *blogv1.Ghost) error {
// Update the status of the Ghost object
if err := r.Status().Update(ctx, ghost); err != nil {
return err
}

return nil
}
</code></pre>
<p>And finally our reconcile function should be replaced with the following snippet.</p>
Expand Down

0 comments on commit ebcf5a6

Please sign in to comment.