Skip to content

Commit 5d74cef

Browse files
Merge pull request #300 from perdasilva/sync_05_03
Sync 05 03
2 parents 29bb28f + 8b6a36b commit 5d74cef

File tree

12 files changed

+422
-53
lines changed

12 files changed

+422
-53
lines changed

staging/operator-lifecycle-manager/.goreleaser.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,13 @@ changelog:
132132
- '^test:'
133133
release:
134134
draft: true
135+
header: |
136+
## Install
137+
138+
### Scripted
139+
140+
```
141+
curl -L https://github.com/operator-framework/operator-lifecycle-manager/releases/download/{{ .Tag }}/install.sh -o install.sh
142+
chmod +x install.sh
143+
./install.sh {{ .Tag }}
144+
```

staging/operator-lifecycle-manager/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@ release: manifests
230230
docker pull $(IMAGE_REPO):$(ver)
231231
$(MAKE) target=upstream ver=$(ver) quickstart=true package
232232

233-
verify-release: release
234-
$(MAKE) diff
235-
236233
package: olmref=$(shell docker inspect --format='{{index .RepoDigests 0}}' $(IMAGE_REPO):$(ver))
237234
package:
238235
ifndef target

staging/operator-lifecycle-manager/pkg/controller/install/certresources.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,12 @@ func (i *StrategyDeploymentInstaller) installCertRequirements(strategy Strategy)
185185
}
186186

187187
// Create the CA
188-
expiration := time.Now().Add(DefaultCertValidFor)
188+
expiration, _ := CalculateCertExpirationAndRotateAt()
189189
ca, err := certs.GenerateCA(expiration, Organization)
190190
if err != nil {
191191
logger.Debug("failed to generate CA")
192192
return nil, err
193193
}
194-
rotateAt := expiration.Add(-1 * DefaultCertMinFresh)
195194

196195
for n, sddSpec := range strategyDetailsDeployment.DeploymentSpecs {
197196
certResources := i.certResourcesForDeployment(sddSpec.Name)
@@ -202,7 +201,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirements(strategy Strategy)
202201
}
203202

204203
// Update the deployment for each certResource
205-
newDepSpec, caPEM, err := i.installCertRequirementsForDeployment(sddSpec.Name, ca, rotateAt, sddSpec.Spec, getServicePorts(certResources))
204+
newDepSpec, caPEM, err := i.installCertRequirementsForDeployment(sddSpec.Name, ca, expiration, sddSpec.Spec, getServicePorts(certResources))
206205
if err != nil {
207206
return nil, err
208207
}
@@ -223,7 +222,13 @@ func ShouldRotateCerts(csv *v1alpha1.ClusterServiceVersion) bool {
223222
return false
224223
}
225224

226-
func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deploymentName string, ca *certs.KeyPair, rotateAt time.Time, depSpec appsv1.DeploymentSpec, ports []corev1.ServicePort) (*appsv1.DeploymentSpec, []byte, error) {
225+
func CalculateCertExpirationAndRotateAt() (expiration time.Time, rotateAt time.Time) {
226+
expiration = time.Now().Add(DefaultCertValidFor)
227+
rotateAt = expiration.Add(-1 * DefaultCertMinFresh)
228+
return
229+
}
230+
231+
func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deploymentName string, ca *certs.KeyPair, expiration time.Time, depSpec appsv1.DeploymentSpec, ports []corev1.ServicePort) (*appsv1.DeploymentSpec, []byte, error) {
227232
logger := log.WithFields(log.Fields{})
228233

229234
// Create a service for the deployment
@@ -263,7 +268,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
263268
fmt.Sprintf("%s.%s", service.GetName(), i.owner.GetNamespace()),
264269
fmt.Sprintf("%s.%s.svc", service.GetName(), i.owner.GetNamespace()),
265270
}
266-
servingPair, err := certGenerator.Generate(rotateAt, Organization, ca, hosts)
271+
servingPair, err := certGenerator.Generate(expiration, Organization, ca, hosts)
267272
if err != nil {
268273
logger.Warnf("could not generate signed certs for hosts %v", hosts)
269274
return nil, nil, err

staging/operator-lifecycle-manager/pkg/controller/operators/catalog/operator.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,7 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
259259

260260
operatorGroupInformer := crInformerFactory.Operators().V1().OperatorGroups()
261261
op.lister.OperatorsV1().RegisterOperatorGroupLister(metav1.NamespaceAll, operatorGroupInformer.Lister())
262-
ogQueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ogs")
263-
op.ogQueueSet.Set(metav1.NamespaceAll, ogQueue)
264-
operatorGroupQueueInformer, err := queueinformer.NewQueueInformer(
265-
ctx,
266-
queueinformer.WithLogger(op.logger),
267-
queueinformer.WithQueue(ogQueue),
268-
queueinformer.WithInformer(operatorGroupInformer.Informer()),
269-
queueinformer.WithSyncer(queueinformer.LegacySyncHandler(op.syncResolvingNamespace).ToSyncer()),
270-
)
271-
if err != nil {
272-
return nil, err
273-
}
274-
if err := op.RegisterQueueInformer(operatorGroupQueueInformer); err != nil {
262+
if err := op.RegisterInformer(operatorGroupInformer.Informer()); err != nil {
275263
return nil, err
276264
}
277265

staging/operator-lifecycle-manager/pkg/controller/operators/olm/operator.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,10 +1888,19 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
18881888
return
18891889
}
18901890

1891-
if out.HasCAResources() {
1891+
// Only update certificate status if:
1892+
// - the CSV has CAResources; and
1893+
// - the certificate lastUpdated and rotateAt timestamps have not already been set, or the certificate should be rotated
1894+
// Note: the code here is a bit wonky and it wasn't clear how to clean it up without some major refactoring:
1895+
// the installer is in charge of generating and rotating the certificates. It detects whether a certificate should be rotated by
1896+
// looking at the csv.status.RotateAt value. But, it does not update this value or surface
1897+
// the certificate expiry information. So, the rotatedAt value is to be re-calculated here. This is bad because you have
1898+
// two different components doing the same thing (installer and operator are both calculating RotateAt). If we're not careful
1899+
// there could be skew
1900+
// See pkg/controller/install/certresources.go
1901+
if shouldUpdateCertificateDates(out) {
18921902
now := metav1.Now()
1893-
expiration := now.Add(install.DefaultCertValidFor)
1894-
rotateAt := expiration.Add(-1 * install.DefaultCertMinFresh)
1903+
_, rotateAt := install.CalculateCertExpirationAndRotateAt()
18951904
rotateTime := metav1.NewTime(rotateAt)
18961905
out.Status.CertsLastUpdated = &now
18971906
out.Status.CertsRotateAt = &rotateTime
@@ -2522,3 +2531,11 @@ func (a *Operator) ensureLabels(in *v1alpha1.ClusterServiceVersion, labelSets ..
25222531
out, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(out.GetNamespace()).Update(context.TODO(), out, metav1.UpdateOptions{})
25232532
return out, err
25242533
}
2534+
2535+
// shouldUpdateCertificateDates checks the csv status to decide whether
2536+
// status.CertsLastUpdated and status.CertsRotateAt should be updated
2537+
// returns true if the CSV has CAResources and status.RotatedAt is not set OR its time to rotate the certificates
2538+
func shouldUpdateCertificateDates(csv *v1alpha1.ClusterServiceVersion) bool {
2539+
isNotSet := csv.Status.CertsRotateAt == nil || csv.Status.CertsRotateAt.IsZero()
2540+
return csv.HasCAResources() && (isNotSet || install.ShouldRotateCerts(csv))
2541+
}

0 commit comments

Comments
 (0)