Skip to content

Commit

Permalink
WIP Move the Service controller to use the new controller model.
Browse files Browse the repository at this point in the history
Fixes: #1134
  • Loading branch information
mattmoor committed Jun 14, 2018
1 parent 8b3a616 commit 3cc5ec6
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 97 deletions.
13 changes: 6 additions & 7 deletions pkg/apis/serving/v1alpha1/revision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,12 @@ func (rs *RevisionStatus) MarkContainerMissing(message string) {
}

func (rs *RevisionStatus) checkAndMarkReady() {
ra := rs.GetCondition(RevisionConditionResourcesAvailable)
if ra == nil || ra.Status != corev1.ConditionTrue {
return
}
ch := rs.GetCondition(RevisionConditionContainerHealthy)
if ch == nil || ch.Status != corev1.ConditionTrue {
return
rct := []RevisionConditionType{RevisionConditionContainerHealthy, RevisionConditionResourcesAvailable}
for _, cond := range rct {
c := rs.GetCondition(cond)
if c == nil || c.Status != corev1.ConditionTrue {
return
}
}
rs.markReady()
}
Expand Down
73 changes: 72 additions & 1 deletion pkg/apis/serving/v1alpha1/service_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ const (
// ServiceConditionReady is set when the service is configured
// and has available backends ready to receive traffic.
ServiceConditionReady ServiceConditionType = "Ready"
// ServiceConditionRouteReady is set when the service's underlying
// route has reported readiness.
ServiceConditionRouteReady ServiceConditionType = "RouteReady"
// ServiceConditionConfigurationReady is set when the service's underlying
// configuration has reported readiness.
ServiceConditionConfigurationReady ServiceConditionType = "ConfigurationReady"
)

type ServiceStatus struct {
Expand Down Expand Up @@ -183,7 +189,8 @@ func (ss *ServiceStatus) RemoveCondition(t ServiceConditionType) {
}

func (ss *ServiceStatus) InitializeConditions() {
sct := []ServiceConditionType{ServiceConditionReady}
sct := []ServiceConditionType{ServiceConditionReady,
ServiceConditionConfigurationReady, ServiceConditionRouteReady}
for _, cond := range sct {
if rc := ss.GetCondition(cond); rc == nil {
ss.setCondition(&ServiceCondition{
Expand All @@ -193,3 +200,67 @@ func (ss *ServiceStatus) InitializeConditions() {
}
}
}

func (ss *ServiceStatus) PropagateConfiguration(cs ConfigurationStatus) {
cc := cs.GetCondition(ConfigurationConditionReady)
if cc == nil {
return
}
sct := []ServiceConditionType{ServiceConditionConfigurationReady}
// If the underlying Configuration reported failure, then bubble it up.
if cc.Status == corev1.ConditionFalse {
sct = append(sct, ServiceConditionReady)
}
for _, cond := range sct {
ss.setCondition(&ServiceCondition{
Type: cond,
Status: cc.Status,
Reason: cc.Reason,
Message: cc.Message,
})
}
if cc.Status == corev1.ConditionTrue {
ss.checkAndMarkReady()
}
}

func (ss *ServiceStatus) PropagateRoute(rs RouteStatus) {
rc := rs.GetCondition(RouteConditionReady)
if rc == nil {
return
}
sct := []ServiceConditionType{ServiceConditionRouteReady}
// If the underlying Route reported failure, then bubble it up.
if rc.Status == corev1.ConditionFalse {
sct = append(sct, ServiceConditionReady)
}
for _, cond := range sct {
ss.setCondition(&ServiceCondition{
Type: cond,
Status: rc.Status,
Reason: rc.Reason,
Message: rc.Message,
})
}
if rc.Status == corev1.ConditionTrue {
ss.checkAndMarkReady()
}
}

func (ss *ServiceStatus) checkAndMarkReady() {
sct := []ServiceConditionType{ServiceConditionConfigurationReady, ServiceConditionRouteReady}
for _, cond := range sct {
c := ss.GetCondition(cond)
if c == nil || c.Status != corev1.ConditionTrue {
return
}
}
ss.markReady()
}

func (ss *ServiceStatus) markReady() {
ss.setCondition(&ServiceCondition{
Type: ServiceConditionReady,
Status: corev1.ConditionTrue,
})
}
2 changes: 1 addition & 1 deletion pkg/controller/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Controller struct {

buildClientSet buildclientset.Interface

// lister indexes properties about Configuration
// listers index properties about resources
lister listers.ConfigurationLister
revisionLister listers.RevisionLister
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func GetElaK8SServiceName(u *v1alpha1.Route) string {
return u.Name + "-service"
}

func GetServiceConfigurationName(u *v1alpha1.Service) string {
return u.Name
}

func GetServiceRouteName(u *v1alpha1.Service) string {
return u.Name
}

func GetElaK8SActivatorServiceName() string {
return "activator-service"
}
Expand Down
Loading

0 comments on commit 3cc5ec6

Please sign in to comment.