Skip to content

Commit

Permalink
MGMT-15598: Add a parameter to manifest list to disable filter (#5498)
Browse files Browse the repository at this point in the history
Recently we made a change to the manifest list to filter out the system
generated manifests when listing them.

This has led to issues with data gathering for triage which requires
full access to all manifests, system generated or otherwise.

I have introduced a boolean parameter IncludeSystemGenerated which
defaults to false. When set to true, the manifest list endpoint will
show all manifests, irrespective of how they were created.

It is intended that we will make a change in assisted-test-infra that
will send this parameter.
  • Loading branch information
paul-maidment committed Sep 28, 2023
1 parent 8450824 commit 4658458
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 7 deletions.
48 changes: 47 additions & 1 deletion client/manifests/v2_list_cluster_manifests_parameters.go

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

2 changes: 1 addition & 1 deletion internal/manifests/manifests.go
Expand Up @@ -176,7 +176,7 @@ func (m *Manifests) ListClusterManifestsInternal(ctx context.Context, params ope
if err != nil {
return nil, err
}
if isUserManifest {
if isUserManifest || swag.BoolValue(params.IncludeSystemGenerated) {
manifests = append(manifests, &models.Manifest{FileName: filename, Folder: folder})
}
}
Expand Down
91 changes: 90 additions & 1 deletion internal/manifests/manifests_test.go
Expand Up @@ -585,6 +585,57 @@ invalid YAML content: {
})

Context("V2ListClusterManifests", func() {

It("should not filter system manifests if requested to show all", func() {
manifests := []models.Manifest{
{
FileName: "file-1.yaml",
Folder: validFolder,
},
{
FileName: "file-2.yaml",
Folder: defaultFolder,
},
{
FileName: "file-3.yaml",
Folder: defaultFolder,
},
}

clusterID := registerCluster().ID
files := make([]string, 0)

mockUpload(len(manifests))

manifestMetadataPrefix := filepath.Join(clusterID.String(), "manifest-attributes")
for _, file := range manifests {
mockS3Client.EXPECT().DoesObjectExist(ctx, filepath.Join(clusterID.String(), constants.ManifestFolder, "openshift", file.FileName)).Return(false, nil).AnyTimes()
mockS3Client.EXPECT().DoesObjectExist(ctx, filepath.Join(clusterID.String(), constants.ManifestFolder, "manifests", file.FileName)).Return(false, nil).AnyTimes()
files = append(files, getObjectName(clusterID, file.Folder, file.FileName))
addManifestToCluster(clusterID, contentYaml, file.FileName, file.Folder)
if file.FileName == "file-2.yaml" {
mockS3Client.EXPECT().DoesObjectExist(ctx, filepath.Join(manifestMetadataPrefix, file.Folder, file.FileName, constants.ManifestSourceUserSupplied)).Return(false, nil).Times(1)
} else {
mockS3Client.EXPECT().DoesObjectExist(ctx, filepath.Join(manifestMetadataPrefix, file.Folder, file.FileName, constants.ManifestSourceUserSupplied)).Return(true, nil).Times(1)
}
}
mockListByPrefix(clusterID, files)

includeSystemGenerated := true
response := manifestsAPI.V2ListClusterManifests(ctx, operations.V2ListClusterManifestsParams{
ClusterID: *clusterID,
IncludeSystemGenerated: &includeSystemGenerated,
})
Expect(response).Should(BeAssignableToTypeOf(operations.NewV2ListClusterManifestsOK()))
responsePayload := response.(*operations.V2ListClusterManifestsOK)
Expect(responsePayload.Payload).ShouldNot(BeNil())
Expect(len(responsePayload.Payload)).To(Equal(len(manifests)))

for i := range manifests {
Expect(manifests).To(ContainElement(*responsePayload.Payload[i]))
}
})

It("lists manifest from different folders", func() {
manifests := []models.Manifest{
{
Expand Down Expand Up @@ -1159,6 +1210,42 @@ invalid YAML content: {
})

Describe("ListClusterManifestsInternal", func() {

It("Should list both system generated and user manifests if IncludeSystemGenerated is true", func() {
clusterId := registerCluster().ID
manifests := []string{
filepath.Join(clusterId.String(), constants.ManifestFolder, "openshift", "system-generated-manifest.yaml"),
filepath.Join(clusterId.String(), constants.ManifestFolder, "openshift", "user-generated-manifest.yaml"),
}
objectName := filepath.Join(clusterId.String(), constants.ManifestFolder)
mockS3Client.EXPECT().ListObjectsByPrefix(ctx, objectName).Return(manifests, nil).Times(1)
mockS3Client.EXPECT().DoesObjectExist(
ctx,
filepath.Join(
clusterId.String(),
constants.ManifestMetadataFolder,
"openshift",
"system-generated-manifest.yaml", "user-supplied")).Return(false, nil).Times(1)
mockS3Client.EXPECT().DoesObjectExist(
ctx,
filepath.Join(
clusterId.String(),
constants.ManifestMetadataFolder,
"openshift",
"user-generated-manifest.yaml", "user-supplied")).Return(true, nil).Times(1)
includeSystemGenerated := true
listedManifests, err := manifestsAPI.ListClusterManifestsInternal(ctx, operations.V2ListClusterManifestsParams{
ClusterID: *clusterId,
IncludeSystemGenerated: &includeSystemGenerated,
})
Expect(err).NotTo(HaveOccurred())
Expect(len(listedManifests)).To(Equal(2))
Expect(listedManifests[0].Folder).To(Equal("openshift"))
Expect(listedManifests[0].FileName).To(Equal("system-generated-manifest.yaml"))
Expect(listedManifests[1].Folder).To(Equal("openshift"))
Expect(listedManifests[1].FileName).To(Equal("user-generated-manifest.yaml"))
})

It("Should be able to list only user manifests if user and non user manifests are present", func() {
clusterId := registerCluster().ID
manifests := []string{
Expand All @@ -1181,8 +1268,10 @@ invalid YAML content: {
constants.ManifestMetadataFolder,
"openshift",
"user-generated-manifest.yaml", "user-supplied")).Return(true, nil).Times(1)
includeSystemGenerated := false
listedManifests, err := manifestsAPI.ListClusterManifestsInternal(ctx, operations.V2ListClusterManifestsParams{
ClusterID: *clusterId,
ClusterID: *clusterId,
IncludeSystemGenerated: &includeSystemGenerated,
})
Expect(err).NotTo(HaveOccurred())
Expect(len(listedManifests)).To(Equal(1))
Expand Down
14 changes: 14 additions & 0 deletions restapi/embedded_spec.go

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

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

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

6 changes: 6 additions & 0 deletions swagger.yaml
Expand Up @@ -2846,6 +2846,12 @@ paths:
type: string
format: uuid
required: true
- in: query
name: include_system_generated
description: Include system generated manifests in results? Default is false.
type: boolean
required: false
default: false
responses:
"200":
description: Success.
Expand Down

0 comments on commit 4658458

Please sign in to comment.