generated from kedacore/github-template
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Operator is aware about changes on underlying ScaledObject (#901)
* Operator is aware about changes on underlying ScaledObject Signed-off-by: Jorge Turrado <[email protected]> * . Signed-off-by: Jorge Turrado <[email protected]> * . Signed-off-by: Jorge Turrado <[email protected]> * Update CHANGELOG.md Co-authored-by: Tom Kerkhove <[email protected]> Signed-off-by: Jorge Turrado Ferrero <[email protected]> --------- Signed-off-by: Jorge Turrado <[email protected]> Signed-off-by: Jorge Turrado Ferrero <[email protected]> Co-authored-by: Tom Kerkhove <[email protected]>
- Loading branch information
1 parent
dbac89d
commit e6896c2
Showing
10 changed files
with
182 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package v1alpha1 | ||
|
||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
// +kubebuilder:validation:Enum=Ready | ||
|
||
// HTTPScaledObjectCreationStatus describes the creation status | ||
// of the scaler's additional resources such as Services, Ingresses and Deployments | ||
type HTTPScaledObjectCreationStatus string | ||
|
||
const ( | ||
// Ready indicates the object is fully created | ||
Ready HTTPScaledObjectCreationStatus = "Ready" | ||
) | ||
|
||
// +kubebuilder:validation:Enum=ErrorCreatingAppScaledObject;AppScaledObjectCreated;TerminatingResources;AppScaledObjectTerminated;AppScaledObjectTerminationError;PendingCreation;HTTPScaledObjectIsReady; | ||
|
||
// HTTPScaledObjectConditionReason describes the reason why the condition transitioned | ||
type HTTPScaledObjectConditionReason string | ||
|
||
const ( | ||
ErrorCreatingAppScaledObject HTTPScaledObjectConditionReason = "ErrorCreatingAppScaledObject" | ||
AppScaledObjectCreated HTTPScaledObjectConditionReason = "AppScaledObjectCreated" | ||
TerminatingResources HTTPScaledObjectConditionReason = "TerminatingResources" | ||
AppScaledObjectTerminated HTTPScaledObjectConditionReason = "AppScaledObjectTerminated" | ||
AppScaledObjectTerminationError HTTPScaledObjectConditionReason = "AppScaledObjectTerminationError" | ||
PendingCreation HTTPScaledObjectConditionReason = "PendingCreation" | ||
HTTPScaledObjectIsReady HTTPScaledObjectConditionReason = "HTTPScaledObjectIsReady" | ||
) | ||
|
||
// HTTPScaledObjectCondition stores the condition state | ||
type HTTPScaledObjectCondition struct { | ||
// Timestamp of the condition | ||
// +optional | ||
Timestamp string `json:"timestamp" description:"Timestamp of this condition"` | ||
// Type of condition | ||
// +required | ||
Type HTTPScaledObjectCreationStatus `json:"type" description:"type of status condition"` | ||
// Status of the condition, one of True, False, Unknown. | ||
// +required | ||
Status metav1.ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"` | ||
// Reason for the condition's last transition. | ||
// +optional | ||
Reason HTTPScaledObjectConditionReason `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"` | ||
// Message indicating details about the transition. | ||
// +optional | ||
Message string `json:"message,omitempty" description:"human-readable message indicating details about last transition"` | ||
} | ||
|
||
type Conditions []HTTPScaledObjectCondition | ||
|
||
// GetReadyCondition returns Condition of type Ready | ||
func (c *Conditions) GetReadyCondition() HTTPScaledObjectCondition { | ||
if *c == nil { | ||
c = GetInitializedConditions() | ||
} | ||
return c.getCondition(Ready) | ||
} | ||
|
||
// GetInitializedConditions returns Conditions initialized to the default -> Status: Unknown | ||
func GetInitializedConditions() *Conditions { | ||
return &Conditions{{Type: Ready, Status: metav1.ConditionUnknown}} | ||
} | ||
|
||
// IsTrue is true if the condition is True | ||
func (c *HTTPScaledObjectCondition) IsTrue() bool { | ||
if c == nil { | ||
return false | ||
} | ||
return c.Status == metav1.ConditionTrue | ||
} | ||
|
||
// IsFalse is true if the condition is False | ||
func (c *HTTPScaledObjectCondition) IsFalse() bool { | ||
if c == nil { | ||
return false | ||
} | ||
return c.Status == metav1.ConditionFalse | ||
} | ||
|
||
func (c Conditions) getCondition(conditionType HTTPScaledObjectCreationStatus) HTTPScaledObjectCondition { | ||
for i := range c { | ||
if c[i].Type == conditionType { | ||
return c[i] | ||
} | ||
} | ||
return HTTPScaledObjectCondition{} | ||
} |
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.
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
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,52 @@ | ||
package util | ||
|
||
import ( | ||
kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" | ||
"k8s.io/apimachinery/pkg/api/equality" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
|
||
"github.com/kedacore/http-add-on/operator/apis/http/v1alpha1" | ||
) | ||
|
||
type HTTPScaledObjectReadyConditionPredicate struct { | ||
predicate.Funcs | ||
} | ||
|
||
func (HTTPScaledObjectReadyConditionPredicate) Update(e event.UpdateEvent) bool { | ||
if e.ObjectOld == nil || e.ObjectNew == nil { | ||
return false | ||
} | ||
|
||
var newReadyCondition, oldReadyCondition v1alpha1.HTTPScaledObjectCondition | ||
|
||
oldObj, ok := e.ObjectOld.(*v1alpha1.HTTPScaledObject) | ||
if !ok { | ||
return false | ||
} | ||
oldReadyCondition = oldObj.Status.Conditions.GetReadyCondition() | ||
|
||
newObj, ok := e.ObjectNew.(*v1alpha1.HTTPScaledObject) | ||
if !ok { | ||
return false | ||
} | ||
newReadyCondition = newObj.Status.Conditions.GetReadyCondition() | ||
|
||
// False/Unknown -> True | ||
if !oldReadyCondition.IsTrue() && newReadyCondition.IsTrue() { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
type ScaledObjectSpecChangedPredicate struct { | ||
predicate.Funcs | ||
} | ||
|
||
func (ScaledObjectSpecChangedPredicate) Update(e event.UpdateEvent) bool { | ||
newObj := e.ObjectNew.(*kedav1alpha1.ScaledObject) | ||
oldObj := e.ObjectOld.(*kedav1alpha1.ScaledObject) | ||
|
||
return !equality.Semantic.DeepDerivative(newObj.Spec, oldObj.Spec) | ||
} |