Skip to content

Commit 1d24f5a

Browse files
authored
add revision to bundles (#580)
* add revision to bundles * data first
1 parent 21c84f3 commit 1d24f5a

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

internal/controller/styra/system_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ func (r *SystemReconciler) reconcileSystemBundle(
821821
Name: uniqueName,
822822
ObjectStorage: objectStorage,
823823
Requirements: requirements,
824+
Revision: bundleRevision(),
824825
}
825826
err := r.OCP.PutBundle(ctx, bundle)
826827

@@ -830,6 +831,14 @@ func (r *SystemReconciler) reconcileSystemBundle(
830831
return ctrl.Result{}, nil
831832
}
832833

834+
// bundleRevision produces a string containing the commit sha for each git requirement
835+
// and the sha256 hash of the concatenated hashes of all datasources,
836+
// for example "data:sha256,gitsource1:commitsha1,requirement1:commitsha2"
837+
func bundleRevision() string {
838+
return `$"data:{crypto.sha256(concat("", {x | x := input.sources[_].sql.hash}))},` +
839+
`{concat(",", {sprintf("%s:%s", [y, x]) | some y; x := input.sources[y].git.commit})}"`
840+
}
841+
833842
func (r *SystemReconciler) reconcileSystemSource(
834843
ctx context.Context,
835844
log logr.Logger,

pkg/ocp/bundles.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ const (
3030
endpointV1Bundles = "/v1/bundles"
3131
)
3232

33-
// BundleConfig represents the configuration of a bundle in the OCP APIs.
34-
type BundleConfig struct {
35-
Name string `json:"-" yaml:"-"`
36-
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
37-
ObjectStorage ObjectStorage `json:"object_storage,omitempty" yaml:"object_storage,omitempty"`
38-
Requirements []Requirement `json:"requirements,omitempty" yaml:"requirements,omitempty"`
39-
ExcludedFiles []string `json:"excluded_files,omitempty" yaml:"excluded_files,omitempty"`
40-
}
41-
4233
// ObjectStorage represents the object storage configuration for a bundle.
4334
type ObjectStorage struct {
4435
AmazonS3 *AmazonS3 `json:"aws,omitempty" yaml:"aws,omitempty"`
@@ -84,6 +75,7 @@ type PutBundleRequest struct {
8475
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
8576
ObjectStorage ObjectStorage `json:"object_storage,omitempty" yaml:"object_storage,omitempty"`
8677
Requirements []Requirement `json:"requirements,omitempty" yaml:"requirements,omitempty"`
78+
Revision string `json:"revision,omitempty" yaml:"revision,omitempty"`
8779
ExcludedFiles []string `json:"excluded_files,omitempty" yaml:"excluded_files,omitempty"`
8880
}
8981

test/integration/controller/system_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,8 @@ var _ = ginkgo.Describe("SystemReconciler.ReconcileOCPSystem", ginkgo.Label("int
26292629
Source: "default-ocp-system",
26302630
},
26312631
},
2632+
Revision: `$"data:{crypto.sha256(concat("", {x | x := input.sources[_].sql.hash}))},` +
2633+
`{concat(",", {sprintf("%s:%s", [y, x]) | some y; x := input.sources[y].git.commit})}"`,
26322634
}).Return(nil).Once()
26332635

26342636
// Called in reconcileS3Credentials
@@ -2688,6 +2690,8 @@ var _ = ginkgo.Describe("SystemReconciler.ReconcileOCPSystem", ginkgo.Label("int
26882690
Source: "default-ocp-system",
26892691
},
26902692
},
2693+
Revision: `$"data:{crypto.sha256(concat("", {x | x := input.sources[_].sql.hash}))},` +
2694+
`{concat(",", {sprintf("%s:%s", [y, x]) | some y; x := input.sources[y].git.commit})}"`,
26912695
}).Return(nil).Once()
26922696

26932697
// Called in reconcileS3Credentials
@@ -2741,6 +2745,8 @@ var _ = ginkgo.Describe("SystemReconciler.ReconcileOCPSystem", ginkgo.Label("int
27412745
Source: "default-ocp-system",
27422746
},
27432747
},
2748+
Revision: `$"data:{crypto.sha256(concat("", {x | x := input.sources[_].sql.hash}))},` +
2749+
`{concat(",", {sprintf("%s:%s", [y, x]) | some y; x := input.sources[y].git.commit})}"`,
27442750
}).Return(nil).Once()
27452751

27462752
// Called in reconcileS3Credentials

0 commit comments

Comments
 (0)