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

Commit

Permalink
Fix MRC status (#4856)
Browse files Browse the repository at this point in the history
* Fix MRC status

Signed-off-by: Keith Mattix II <[email protected]>

* Address PR comments

Signed-off-by: Keith Mattix II <[email protected]>
  • Loading branch information
keithmattix authored Jun 29, 2022
1 parent 4a1b993 commit bb007fd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
3 changes: 3 additions & 0 deletions charts/osm/templates/osm-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ rules:
- apiGroups: ["config.openservicemesh.io"]
resources: ["meshconfigs", "meshrootcertificates"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["config.openservicemesh.io"]
resources: ["meshrootcertificates/status"]
verbs: ["update"]
- apiGroups: ["split.smi-spec.io"]
resources: ["trafficsplits"]
verbs: ["list", "get", "watch"]
Expand Down
2 changes: 1 addition & 1 deletion cmd/osm-bootstrap/crds/config_mesh_root_certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
storage: true
additionalPrinterColumns:
- description: Current state of the MeshRootCertificate config
jsonPath: .status.currentState
jsonPath: .status.state
name: State
type: string
schema:
Expand Down
18 changes: 14 additions & 4 deletions cmd/osm-bootstrap/osm-bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func (b *bootstrap) createMeshRootCertificate() error {
if err != nil {
return err
}
_, err = b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Create(context.TODO(), defaultMeshRootCertificate, metav1.CreateOptions{})
createdMRC, err := b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Create(context.TODO(), defaultMeshRootCertificate, metav1.CreateOptions{})
if apierrors.IsAlreadyExists(err) {
log.Info().Msgf("MeshRootCertificate already exists in %s. Skip creating.", b.namespace)
return nil
Expand All @@ -404,6 +404,19 @@ func (b *bootstrap) createMeshRootCertificate() error {
return err
}

createdMRC.Status = configv1alpha2.MeshRootCertificateStatus{
State: constants.MRCStateActive,
}

_, err = b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).UpdateStatus(context.Background(), createdMRC, metav1.UpdateOptions{})
if apierrors.IsAlreadyExists(err) {
log.Info().Msgf("MeshRootCertificate statys already exists in %s. Skip creating.", b.namespace)
}

if err != nil {
return err
}

log.Info().Msgf("Successfully created MeshRootCertificate %s in %s.", meshRootCertificateName, b.namespace)
return nil
}
Expand All @@ -428,9 +441,6 @@ func buildMeshRootCertificate(presetMeshRootCertificateConfigMap *corev1.ConfigM
},
},
Spec: presetMeshRootCertificateSpec,
Status: configv1alpha2.MeshRootCertificateStatus{
State: constants.MRCStateActive,
},
}

return mrc, util.CreateApplyAnnotation(mrc, unstructured.UnstructuredJSONScheme)
Expand Down
15 changes: 12 additions & 3 deletions cmd/osm-bootstrap/osm-bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,19 @@ func TestCreateMeshRootCertificate(t *testing.T) {
}

err := b.createMeshRootCertificate()
assert.Equal(tc.expectErr, err != nil)
if !tc.expectErr {
assert.NoError(err)
} else {
assert.Error(err)
}

_, err = b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Get(context.TODO(), meshRootCertificateName, metav1.GetOptions{})
assert.Equal(tc.expectDefaultMeshRootCertificate, err == nil)
mrc, err := b.configClient.ConfigV1alpha2().MeshRootCertificates(b.namespace).Get(context.TODO(), meshRootCertificateName, metav1.GetOptions{})
if tc.expectDefaultMeshRootCertificate {
assert.NoError(err)
assert.Equal(constants.MRCStateActive, mrc.Status.State)
} else {
assert.Error(err)
}
})
}
}
Expand Down

0 comments on commit bb007fd

Please sign in to comment.