Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 18 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ required = [
[[constraint]]
name = "github.com/openshift/api"
branch = "master"

[[constraint]]
name = "github.com/openshift/cluster-version-operator"
revision = "a5a76d5118048d0e969e6bd3d40cb4c36591d171"
3 changes: 3 additions & 0 deletions cmd/cluster-ingress-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func main() {
resyncPeriod := 10 * time.Minute
logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod)
sdk.Watch(resource, kind, namespace, resyncPeriod)
// TODO Define and use a named constant for the router namespace.
sdk.Watch("v1", "Service", "openshift-cluster-ingress-router", resyncPeriod)
sdk.Watch("v1", "Endpoints", "openshift-cluster-ingress-router", resyncPeriod)
sdk.Handle(stub.NewHandler())
sdk.Run(context.TODO())
}
17 changes: 17 additions & 0 deletions manifests/00-cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ rules:
- list
- watch

- apiGroups:
- operatorstatus.openshift.io
resources:
- operatorstatuses
verbs:
- create
- get
- update

- apiGroups:
- ""
resources:
- endpoints
- services
verbs:
- get

# Mirrored from assets/router/cluster-role.yaml
- apiGroups:
- ""
Expand Down
135 changes: 135 additions & 0 deletions pkg/apis/ingress/v1alpha1/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package v1alpha1

import (
"fmt"

operatorv1alpha1 "github.com/openshift/api/operator/v1alpha1"
"github.com/operator-framework/operator-sdk/pkg/sdk"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// setStatusCondition modifies the ClusterIngress object's status by setting the
// specified condition.
func (ci *ClusterIngress) setStatusCondition(condition *operatorv1alpha1.OperatorCondition) {
condition.LastTransitionTime = metav1.Now()

conditions := []operatorv1alpha1.OperatorCondition{}

found := false
for _, c := range ci.Status.Conditions {
if condition.Type == c.Type {
if condition.Status == c.Status &&
condition.Reason == c.Reason &&
condition.Message == c.Message {
return
}

found = true
conditions = append(conditions, *condition)
} else {
conditions = append(conditions, c)
}
}
if !found {
conditions = append(conditions, *condition)
}

ci.Status.Conditions = conditions
}

// SetStatusSyncCondition modifies the ClusterIngress object's status by setting
// its SyncSuccessful condition in accordance with the provided error value.
func (ci *ClusterIngress) SetStatusSyncCondition(err error) {
condition := &operatorv1alpha1.OperatorCondition{
Type: operatorv1alpha1.OperatorStatusTypeSyncSuccessful,
Status: operatorv1alpha1.ConditionTrue,
}

if err != nil {
condition.Status = operatorv1alpha1.ConditionFalse
condition.Reason = "SyncFailed"
condition.Message = err.Error()
}

ci.setStatusCondition(condition)
}

// SetStatusAvailableCondition modifies the ClusterIngress object's status by
// setting its Available condition to the specified status and message.
func (ci *ClusterIngress) SetStatusAvailableCondition(available bool, message string) {
condition := &operatorv1alpha1.OperatorCondition{
Type: operatorv1alpha1.OperatorStatusTypeAvailable,
Status: operatorv1alpha1.ConditionTrue,
}

if !available {
condition.Status = operatorv1alpha1.ConditionFalse
condition.Reason = "ServiceNotReady"
condition.Message = message
}

ci.setStatusCondition(condition)
}

// clusterIngressStatusEqual returns true if and only if the status conditions
// (ignoring LastTransitionTime) and ingresses of the provided ClusterIngress
// objects are equal.
func clusterIngressStatusEqual(oldStatus, newStatus *ClusterIngressStatus) bool {
if len(newStatus.Conditions) != len(oldStatus.Conditions) {
return false
}
for _, conditionA := range oldStatus.Conditions {
foundMatchingCondition := false

for _, conditionB := range newStatus.Conditions {
// Compare every field except LastTransitionTime.
if conditionA.Type == conditionB.Type &&
conditionA.Status == conditionB.Status &&
conditionA.Reason == conditionB.Reason &&
conditionA.Message == conditionB.Message {
foundMatchingCondition = true
break
}
}

if !foundMatchingCondition {
return false
}
}

if len(newStatus.LoadBalancer.Ingress) != len(oldStatus.LoadBalancer.Ingress) {
return false
}
for _, ingressA := range oldStatus.LoadBalancer.Ingress {
foundMatchingIngress := false

for _, ingressB := range newStatus.LoadBalancer.Ingress {
if ingressA == ingressB {
foundMatchingIngress = true
break
}
}

if !foundMatchingIngress {
return false
}
}

return true
}

// UpdateStatus updates the receiver ClusterIngress object's status if it
// differs from the provided ClusterIngress object's status.
func (ci *ClusterIngress) UpdateStatus(oldCi *ClusterIngress) error {
if clusterIngressStatusEqual(&oldCi.Status, &ci.Status) {
return nil
}

if err := sdk.Update(ci); err != nil {
return fmt.Errorf(
"failed to update status of ClusterIngress %q: %v",
ci.Name, err)
}

return nil
}
Loading