Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with rebuilds #917

Merged
merged 1 commit into from
Nov 13, 2023
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
13 changes: 13 additions & 0 deletions pkg/reconciler/artifactbuild/artifactbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const (
PipelineResultGavs = "GAVS"

RebuildAnnotation = "jvmbuildservice.io/rebuild"
//annotation that is applied after a rebuild, it will affect the dependencybuild behaviour
RebuiltAnnotation = "jvmbuildservice.io/rebuilt"
)

type ReconcileArtifactBuild struct {
Expand Down Expand Up @@ -147,6 +149,7 @@ func (r *ReconcileArtifactBuild) handleArtifactBuildReceived(ctx context.Context
return r.handleRebuild(log, ctx, &abr)
} else {
delete(abr.Annotations, RebuildAnnotation)
abr.Annotations[RebuiltAnnotation] = "true"
return reconcile.Result{}, r.client.Update(ctx, &abr)
}
} else if abr.Annotations[RebuildAnnotation] == "failed" {
Expand Down Expand Up @@ -278,6 +281,12 @@ func (r *ReconcileArtifactBuild) handleStateDiscovering(ctx context.Context, log
if err := controllerutil.SetOwnerReference(abr, db, r.scheme); err != nil {
return reconcile.Result{}, err
}
if abr.Annotations != nil && abr.Annotations[RebuiltAnnotation] == "true" {
if db.Annotations == nil {
db.Annotations = map[string]string{}
}
db.Annotations[RebuiltAnnotation] = "true"
}
if err := r.client.Update(ctx, db); err != nil {
return reconcile.Result{}, err
}
Expand All @@ -296,6 +305,7 @@ func (r *ReconcileArtifactBuild) handleStateDiscovering(ctx context.Context, log
case errors.IsNotFound(err):
//no existing build object found, lets create one
db := &v1alpha1.DependencyBuild{}
db.Annotations = map[string]string{}
db.Namespace = abr.Namespace
//TODO: do we in fact need to put depId through GenerateName sanitation algorithm for the name? label value restrictions are more stringent than obj name
db.Name = depId
Expand All @@ -311,6 +321,9 @@ func (r *ReconcileArtifactBuild) handleStateDiscovering(ctx context.Context, log
Private: abr.Status.SCMInfo.Private,
}, Version: abr.Spec.GAV[strings.LastIndex(abr.Spec.GAV, ":")+1:]}

if abr.Annotations != nil && abr.Annotations[RebuiltAnnotation] == "true" {
db.Annotations[RebuiltAnnotation] = "true"
}
//move the state to building
if err := r.updateArtifactState(ctx, log, abr, v1alpha1.ArtifactBuildStateBuilding); err != nil {
return reconcile.Result{}, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/artifactbuild/artifactbuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ func TestStateBuilding(t *testing.T) {
g.Expect(reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{Namespace: metav1.NamespaceDefault, Name: "test"}}))
abr = getABR(client, g)
g.Expect(abr.Status.State).Should(Equal(v1alpha1.ArtifactBuildStateNew))
g.Expect(abr.Annotations[RebuildAnnotation]).Should(Equal("")) //second reconcile removes the annotation
g.Expect(abr.Annotations[RebuildAnnotation]).Should(Equal("")) //second reconcile removes the annotation
g.Expect(abr.Annotations[RebuiltAnnotation]).Should(Equal("true")) //second reconcile removes the annotation
})
t.Run("Contaminated build", func(t *testing.T) {
g := NewGomegaWithT(t)
Expand Down
22 changes: 14 additions & 8 deletions pkg/reconciler/dependencybuild/dependencybuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (r *ReconcileDependencyBuild) handleStateNew(ctx context.Context, log logr.
//should be enough for the build lookup task
additionalMemory = 1024
}
pr.Spec.PipelineSpec, err = r.createLookupBuildInfoPipeline(ctx, log, &db.Spec, jbsConfig, additionalMemory, &systemConfig)
pr.Spec.PipelineSpec, err = r.createLookupBuildInfoPipeline(ctx, log, db, jbsConfig, additionalMemory, &systemConfig)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -959,11 +959,12 @@ func (r *ReconcileDependencyBuild) createRebuiltArtifacts(ctx context.Context, l
return true, nil
}

func (r *ReconcileDependencyBuild) createLookupBuildInfoPipeline(ctx context.Context, log logr.Logger, build *v1alpha1.DependencyBuildSpec, jbsConfig *v1alpha1.JBSConfig, additionalMemory int, systemConfig *v1alpha1.SystemConfig) (*pipelinev1beta1.PipelineSpec, error) {
func (r *ReconcileDependencyBuild) createLookupBuildInfoPipeline(ctx context.Context, log logr.Logger, db *v1alpha1.DependencyBuild, jbsConfig *v1alpha1.JBSConfig, additionalMemory int, systemConfig *v1alpha1.SystemConfig) (*pipelinev1beta1.PipelineSpec, error) {
image, err := r.buildRequestProcessorImage(ctx, log)
if err != nil {
return nil, err
}
build := db.Spec
path := build.ScmInfo.Path
zero := int64(0)
cacheUrl := "https://jvm-build-workspace-artifact-cache-tls." + jbsConfig.Namespace + ".svc.cluster.local"
Expand Down Expand Up @@ -993,13 +994,18 @@ func (r *ReconcileDependencyBuild) createLookupBuildInfoPipeline(ctx context.Con
args = append(args, "--context", path)
}

// Search not only the configured shared registries but the main registry as well.
if registries == "" {
registries = jbsconfig.ImageRegistryToString(jbsConfig.ImageRegistry())
} else {
registries += ";" + jbsconfig.ImageRegistryToString(jbsConfig.ImageRegistry())
//don't look for existing artifacts on a rebuild
if db.Annotations == nil || db.Annotations[artifactbuild.RebuiltAnnotation] != "true" {
// Search not only the configured shared registries but the main registry as well.
if registries == "" {
registries = jbsconfig.ImageRegistryToString(jbsConfig.ImageRegistry())
} else {
registries += ";" + jbsconfig.ImageRegistryToString(jbsConfig.ImageRegistry())
}
}
if registries != "" {
args = append(args, "--registries", registries)
}
args = append(args, "--registries", registries)

if build.ScmInfo.Private {
args = append(args, "--private-repo")
Expand Down
Loading