Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/mbsc/mbsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type MBSC interface {
moduleImageSpec *kmmv1beta1.ModuleImageSpec, action kmmv1beta1.BuildOrSignAction) error
GetImageSpec(mbscObj *kmmv1beta1.ModuleBuildSignConfig, image string) *kmmv1beta1.ModuleBuildSignSpec
SetImageStatus(mbscObj *kmmv1beta1.ModuleBuildSignConfig, image string, action kmmv1beta1.BuildOrSignAction, status kmmv1beta1.BuildOrSignStatus)
GetImageStatus(mbscObj *kmmv1beta1.ModuleBuildSignConfig, image string, action kmmv1beta1.BuildOrSignAction) kmmv1beta1.BuildOrSignStatus
}

type mbsc struct {
Expand Down Expand Up @@ -85,6 +86,15 @@ func (m *mbsc) SetImageStatus(mbscObj *kmmv1beta1.ModuleBuildSignConfig, image s
mbscObj.Status.Images = append(mbscObj.Status.Images, imageState)
}

func (m *mbsc) GetImageStatus(mbscObj *kmmv1beta1.ModuleBuildSignConfig, image string, action kmmv1beta1.BuildOrSignAction) kmmv1beta1.BuildOrSignStatus {
for _, imageState := range mbscObj.Status.Images {
if imageState.Image == image && imageState.Action == action {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to pass the action to get the status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make sure that we get the correct one. MIC is sending request for image and action, if we don't pass action, we might get the status for the previous action

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me why don't we just update the whole status atomically, and remove the imageState.status if we just changed the action and the status wasn't reported yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the status is updated atomically by MBSC controller, but it is updated once the MBSC controller has the result. MIC should never update the status of MBSC object.

return imageState.Status
}
}
return kmmv1beta1.BuildOrSignStatus("")
}

func setModuleImageSpec(mbscObj *kmmv1beta1.ModuleBuildSignConfig, moduleImageSpec *kmmv1beta1.ModuleImageSpec, action kmmv1beta1.BuildOrSignAction) {
specEntry := kmmv1beta1.ModuleBuildSignSpec{
ModuleImageSpec: *moduleImageSpec,
Expand Down
39 changes: 39 additions & 0 deletions internal/mbsc/mbsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,42 @@ var _ = Describe("SetImageSpec", func() {
Expect(testMBSC.Status.Images[2].Action).To(Equal(kmmv1beta1.BuildImage))
})
})

var _ = Describe("GetImageStatus", func() {
testMBSC := kmmv1beta1.ModuleBuildSignConfig{
Status: kmmv1beta1.ModuleBuildSignConfigStatus{
Images: []kmmv1beta1.BuildSignImageState{
{
Image: "image1",
Status: kmmv1beta1.ActionSuccess,
Action: kmmv1beta1.BuildImage,
},
{
Image: "image2",
Status: kmmv1beta1.ActionFailure,
Action: kmmv1beta1.SignImage,
},
},
},
}

mbscAPI := New(nil, nil)

It("get images status for both present and not present statuses", func() {
By("image and action are present")
res := mbscAPI.GetImageStatus(&testMBSC, "image1", kmmv1beta1.BuildImage)
Expect(res).To(Equal(kmmv1beta1.ActionSuccess))

By("image present, action missing")
res = mbscAPI.GetImageStatus(&testMBSC, "image2", kmmv1beta1.BuildImage)
Expect(res).To(Equal(kmmv1beta1.BuildOrSignStatus("")))

By("image missing, action present")
res = mbscAPI.GetImageStatus(&testMBSC, "image3", kmmv1beta1.BuildImage)
Expect(res).To(Equal(kmmv1beta1.BuildOrSignStatus("")))

By("image missing, action missing")
res = mbscAPI.GetImageStatus(&testMBSC, "image3", kmmv1beta1.SignImage)
Expect(res).To(Equal(kmmv1beta1.BuildOrSignStatus("")))
})
})
14 changes: 14 additions & 0 deletions internal/mbsc/mock_mbsc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading