Skip to content

Commit f61307b

Browse files
committed
feat(csv): add succeeded to pending transition on cert refresh
1 parent 7521ffc commit f61307b

File tree

6 files changed

+226
-33
lines changed

6 files changed

+226
-33
lines changed

pkg/api/apis/operators/v1alpha1/clusterserviceversion_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ const (
201201
CSVReasonComponentUnhealthy ConditionReason = "ComponentUnhealthy"
202202
CSVReasonBeingReplaced ConditionReason = "BeingReplaced"
203203
CSVReasonReplaced ConditionReason = "Replaced"
204+
CSVReasonNeedCertRefresh ConditionReason = "NeedCertRefresh"
204205
)
205206

206207
// Conditions appear in the status as a record of state transitions on the ClusterServiceVersion
@@ -288,7 +289,7 @@ type ClusterServiceVersionStatus struct {
288289
RequirementStatus []RequirementStatus `json:"requirementStatus,omitempty"`
289290
// Time to refresh generated owned APIService certs
290291
// +optional
291-
CertRefresh metav1.Time `json:"requirementStatus,omitempty"`
292+
CertRefresh metav1.Time `json:"certRefresh,omitempty"`
292293
}
293294

294295
// ClusterServiceVersion is a Custom Resource of type `ClusterServiceVersionSpec`.

pkg/controller/operators/olm/apiservices.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222
)
2323

2424
const (
25-
// Minimum number of seconds that a min-fresh value can be
25+
// CertMinFreshSecondsThreshold is the minimum number of seconds that a min-fresh value can be
2626
CertMinFreshSecondsThreshold = 10
27-
// Default min-fresh value
27+
// DefaultCertMinFreshSeconds is the default min-fresh value
2828
DefaultCertMinFreshSeconds = 300
29-
// Minimum number of days that a cert can be valid for
29+
// CertValidForDaysThreshold is the minimum number of days that a cert can be valid for
3030
CertValidForDaysThreshold = 1
31-
// Default number of days a cert can be valid for
31+
// DefaultCertValidForDays is the default number of days a cert can be valid for
3232
DefaultCertValidForDays = 730
3333
)
3434

@@ -47,6 +47,15 @@ func (a *Operator) syncAPIServices(obj interface{}) (syncError error) {
4747
return nil
4848
}
4949

50+
func (a *Operator) shouldRefreshCerts(csv *v1alpha1.ClusterServiceVersion) bool {
51+
now := metav1.Now()
52+
if !csv.Status.CertRefresh.IsZero() && csv.Status.CertRefresh.Before(&now) {
53+
return true
54+
}
55+
56+
return false
57+
}
58+
5059
func (a *Operator) isAPIServiceAvailable(apiService *apiregistrationv1.APIService) bool {
5160
for _, c := range apiService.Status.Conditions {
5261
if c.Type == apiregistrationv1.Available && c.Status == apiregistrationv1.ConditionTrue {

pkg/controller/operators/olm/operator.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
335335
logger.Info("scheduling ClusterServiceVersion for install")
336336
out.SetPhaseWithEvent(v1alpha1.CSVPhaseInstallReady, v1alpha1.CSVReasonRequirementsMet, "all requirements found, attempting install", a.recorder)
337337
case v1alpha1.CSVPhaseInstallReady:
338-
339338
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
340339
if strategy == nil {
341340
// parseStrategiesAndUpdateStatus sets CSV status
@@ -373,9 +372,16 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
373372
// parseStrategiesAndUpdateStatus sets CSV status
374373
return
375374
}
375+
376376
if installErr := a.updateInstallStatus(out, installer, strategy, v1alpha1.CSVReasonComponentUnhealthy); installErr != nil {
377377
logger.WithField("strategy", out.Spec.InstallStrategy.StrategyName).Infof("unhealthy component: %s", installErr)
378378
}
379+
380+
// Check if it's time to refresh owned APIService certs
381+
if a.shouldRefreshCerts(out) {
382+
out.SetPhase(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonInstallSuccessful, "owned APIServices need cert refresh")
383+
return
384+
}
379385
case v1alpha1.CSVPhaseReplacing:
380386
// determine CSVs that are safe to delete by finding a replacement chain to a CSV that's running
381387
// since we don't know what order we'll process replacements, we have to guard against breaking that chain

0 commit comments

Comments
 (0)