Skip to content

Commit e6243d4

Browse files
committed
Check if CRLs are downloaded when determining ready status
This fixes OCPBUGS-29894
1 parent 72114ea commit e6243d4

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

pkg/cmd/infra/router/template.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ func (o *TemplateRouterOptions) Run(stopCh <-chan struct{}) error {
634634
if err != nil {
635635
return err
636636
}
637+
checkCRLs := metrics.CRLsUpdated()
637638
checkController := metrics.ControllerLive()
638639
liveChecks := []healthz.HealthChecker{checkController}
639640
if !(isTrue(env("ROUTER_BIND_PORTS_BEFORE_SYNC", ""))) {
@@ -688,7 +689,7 @@ func (o *TemplateRouterOptions) Run(stopCh <-chan struct{}) error {
688689
Name: o.RouterName,
689690
},
690691
LiveChecks: liveChecks,
691-
ReadyChecks: []healthz.HealthChecker{checkBackend, checkSync, metrics.ProcessRunning(stopCh)},
692+
ReadyChecks: []healthz.HealthChecker{checkBackend, checkSync, metrics.ProcessRunning(stopCh), checkCRLs},
692693
}
693694

694695
if tlsConfig, err := makeTLSConfig(30 * time.Second); err != nil {

pkg/router/crl/crl.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os"
1414
"path/filepath"
1515
"strings"
16+
"sync"
1617
"time"
1718

1819
logf "github.com/openshift/router/log"
@@ -66,6 +67,9 @@ var (
6667
CRLFilename = filepath.Join(mtlsLatestSymlink, crlBasename)
6768
// CABundleFilename is the fully qualified path to the currently in use CA bundle.
6869
CABundleFilename = filepath.Join(mtlsLatestSymlink, caBundleBasename)
70+
// crlsUpdated is true when all CRLs have been successfully updated, and false when there are missing CRLs.
71+
crlsUpdated = false
72+
crlsMutex = sync.Mutex{}
6973
)
7074

7175
// authorityKeyIdentifier is a certificate's authority key identifier.
@@ -143,19 +147,24 @@ func ManageCRLs(caBundleFilename string, caUpdateChannel <-chan struct{}, update
143147
log.Error(err, "failed to parse CA bundle", "CA bundle filename", caBundleFilename)
144148
nextUpdate = time.Now().Add(errorBackoffTime)
145149
}
150+
if !shouldHaveCRLs {
151+
SetCRLsUpdated(true)
152+
}
146153
for {
147154
updated := false
148155
if nextUpdate.IsZero() {
149156
log.V(4).Info("no nextUpdate. only watching for CA updates")
150157
select {
151158
case <-caUpdateChannel:
159+
SetCRLsUpdated(false)
152160
caUpdated = true
153161
}
154162
} else {
155163
log.V(4).Info("nextUpdate is at " + nextUpdate.Format(time.RFC3339))
156164
select {
157165
case <-time.After(time.Until(nextUpdate)):
158166
case <-caUpdateChannel:
167+
SetCRLsUpdated(false)
159168
caUpdated = true
160169
}
161170
}
@@ -175,8 +184,9 @@ func ManageCRLs(caBundleFilename string, caUpdateChannel <-chan struct{}, update
175184
nextUpdate = time.Now().Add(errorBackoffTime)
176185
continue
177186
}
178-
// After successfully updating the CRL file, reset caUpdated
187+
// After successfully updating the CRL file, reset caUpdated and mark CRLs as updated
179188
caUpdated = false
189+
SetCRLsUpdated(true)
180190
if updated {
181191
updateCallback(shouldHaveCRLs)
182192
}
@@ -506,3 +516,15 @@ func makeStagingDirectory() (string, error) {
506516
}
507517
return stagingDirName, nil
508518
}
519+
520+
func GetCRLsUpdated() bool {
521+
crlsMutex.Lock()
522+
defer crlsMutex.Unlock()
523+
return crlsUpdated
524+
}
525+
526+
func SetCRLsUpdated(value bool) {
527+
crlsMutex.Lock()
528+
defer crlsMutex.Unlock()
529+
crlsUpdated = value
530+
}

pkg/router/metrics/health.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"k8s.io/apiserver/pkg/server/healthz"
1414

15+
"github.com/openshift/router/pkg/router/crl"
1516
"github.com/openshift/router/pkg/router/metrics/probehttp"
1617
templateplugin "github.com/openshift/router/pkg/router/template"
1718
)
@@ -75,6 +76,15 @@ func ControllerLive() healthz.HealthChecker {
7576

7677
}
7778

79+
func CRLsUpdated() healthz.HealthChecker {
80+
return healthz.NamedCheck("crls-updated", func(r *http.Request) error {
81+
if !crl.GetCRLsUpdated() {
82+
return fmt.Errorf("missing CRLs")
83+
}
84+
return nil
85+
})
86+
}
87+
7888
// ProxyProtocolHTTPBackendAvailable returns a healthz check that verifies a backend supporting
7989
// the HAProxy PROXY protocol responds to a GET to the provided URL with 2xx or 3xx response.
8090
func ProxyProtocolHTTPBackendAvailable(u *url.URL) healthz.HealthChecker {

pkg/router/template/router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ func (r *templateRouter) watchMutualTLSCert() error {
484484
log.V(0).Error(err, "failed to establish watch on mTLS certificate directory")
485485
return nil
486486
}
487+
} else {
488+
crl.SetCRLsUpdated(true)
487489
}
488490
return nil
489491
}

0 commit comments

Comments
 (0)