Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit bb007fd

Browse files
authored
Fix MRC status (#4856)
* Fix MRC status Signed-off-by: Keith Mattix II <[email protected]> * Address PR comments Signed-off-by: Keith Mattix II <[email protected]>
1 parent 4a1b993 commit bb007fd

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

charts/osm/templates/osm-rbac.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ rules:
4343
- apiGroups: ["config.openservicemesh.io"]
4444
resources: ["meshconfigs", "meshrootcertificates"]
4545
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
46+
- apiGroups: ["config.openservicemesh.io"]
47+
resources: ["meshrootcertificates/status"]
48+
verbs: ["update"]
4649
- apiGroups: ["split.smi-spec.io"]
4750
resources: ["trafficsplits"]
4851
verbs: ["list", "get", "watch"]

cmd/osm-bootstrap/crds/config_mesh_root_certificate.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ spec:
3636
storage: true
3737
additionalPrinterColumns:
3838
- description: Current state of the MeshRootCertificate config
39-
jsonPath: .status.currentState
39+
jsonPath: .status.state
4040
name: State
4141
type: string
4242
schema:

cmd/osm-bootstrap/osm-bootstrap.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func (b *bootstrap) createMeshRootCertificate() error {
395395
if err != nil {
396396
return err
397397
}
398-
_, err = b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Create(context.TODO(), defaultMeshRootCertificate, metav1.CreateOptions{})
398+
createdMRC, err := b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Create(context.TODO(), defaultMeshRootCertificate, metav1.CreateOptions{})
399399
if apierrors.IsAlreadyExists(err) {
400400
log.Info().Msgf("MeshRootCertificate already exists in %s. Skip creating.", b.namespace)
401401
return nil
@@ -404,6 +404,19 @@ func (b *bootstrap) createMeshRootCertificate() error {
404404
return err
405405
}
406406

407+
createdMRC.Status = configv1alpha2.MeshRootCertificateStatus{
408+
State: constants.MRCStateActive,
409+
}
410+
411+
_, err = b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).UpdateStatus(context.Background(), createdMRC, metav1.UpdateOptions{})
412+
if apierrors.IsAlreadyExists(err) {
413+
log.Info().Msgf("MeshRootCertificate statys already exists in %s. Skip creating.", b.namespace)
414+
}
415+
416+
if err != nil {
417+
return err
418+
}
419+
407420
log.Info().Msgf("Successfully created MeshRootCertificate %s in %s.", meshRootCertificateName, b.namespace)
408421
return nil
409422
}
@@ -428,9 +441,6 @@ func buildMeshRootCertificate(presetMeshRootCertificateConfigMap *corev1.ConfigM
428441
},
429442
},
430443
Spec: presetMeshRootCertificateSpec,
431-
Status: configv1alpha2.MeshRootCertificateStatus{
432-
State: constants.MRCStateActive,
433-
},
434444
}
435445

436446
return mrc, util.CreateApplyAnnotation(mrc, unstructured.UnstructuredJSONScheme)

cmd/osm-bootstrap/osm-bootstrap_test.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,19 @@ func TestCreateMeshRootCertificate(t *testing.T) {
356356
}
357357

358358
err := b.createMeshRootCertificate()
359-
assert.Equal(tc.expectErr, err != nil)
359+
if !tc.expectErr {
360+
assert.NoError(err)
361+
} else {
362+
assert.Error(err)
363+
}
360364

361-
_, err = b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Get(context.TODO(), meshRootCertificateName, metav1.GetOptions{})
362-
assert.Equal(tc.expectDefaultMeshRootCertificate, err == nil)
365+
mrc, err := b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Get(context.TODO(), meshRootCertificateName, metav1.GetOptions{})
366+
if tc.expectDefaultMeshRootCertificate {
367+
assert.NoError(err)
368+
assert.Equal(constants.MRCStateActive, mrc.Status.State)
369+
} else {
370+
assert.Error(err)
371+
}
363372
})
364373
}
365374
}

0 commit comments

Comments
 (0)