Merge pull request #141 from fluxcd/status-artifact-reset
This commit is contained in:
commit
fa37eea123
9
Makefile
9
Makefile
|
@ -14,7 +14,8 @@ all: manager
|
|||
|
||||
# Run tests
|
||||
test: generate fmt vet manifests api-docs
|
||||
find . -maxdepth 2 -type f -name 'go.mod' -execdir go test ./... -coverprofile cover.out \;
|
||||
go test ./... -coverprofile cover.out
|
||||
cd api; go test ./... -coverprofile cover.out
|
||||
|
||||
# Build manager binary
|
||||
manager: generate fmt vet
|
||||
|
@ -55,11 +56,13 @@ api-docs: gen-crd-api-reference-docs
|
|||
|
||||
# Run go fmt against code
|
||||
fmt:
|
||||
find . -maxdepth 2 -type f -name 'go.mod' -execdir go fmt ./... \;
|
||||
go fmt ./...
|
||||
cd api; go fmt ./...
|
||||
|
||||
# Run go vet against code
|
||||
vet:
|
||||
find . -maxdepth 2 -type f -name 'go.mod' -execdir go vet ./... \;
|
||||
go vet ./...
|
||||
cd api; go vet ./...
|
||||
|
||||
# Generate code
|
||||
generate: controller-gen
|
||||
|
|
|
@ -133,7 +133,6 @@ const (
|
|||
func GitRepositoryProgressing(repository GitRepository) GitRepository {
|
||||
repository.Status.ObservedGeneration = repository.Generation
|
||||
repository.Status.URL = ""
|
||||
repository.Status.Artifact = nil
|
||||
repository.Status.Conditions = []SourceCondition{}
|
||||
SetGitRepositoryCondition(&repository, ReadyCondition, corev1.ConditionUnknown, ProgressingReason, "reconciliation in progress")
|
||||
return repository
|
||||
|
|
|
@ -102,7 +102,6 @@ const (
|
|||
func HelmChartProgressing(chart HelmChart) HelmChart {
|
||||
chart.Status.ObservedGeneration = chart.Generation
|
||||
chart.Status.URL = ""
|
||||
chart.Status.Artifact = nil
|
||||
chart.Status.Conditions = []SourceCondition{}
|
||||
SetHelmChartCondition(&chart, ReadyCondition, corev1.ConditionUnknown, ProgressingReason, "reconciliation in progress")
|
||||
return chart
|
||||
|
|
|
@ -87,7 +87,6 @@ const (
|
|||
func HelmRepositoryProgressing(repository HelmRepository) HelmRepository {
|
||||
repository.Status.ObservedGeneration = repository.Generation
|
||||
repository.Status.URL = ""
|
||||
repository.Status.Artifact = nil
|
||||
repository.Status.Conditions = []SourceCondition{}
|
||||
SetHelmRepositoryCondition(&repository, ReadyCondition, corev1.ConditionUnknown, ProgressingReason, "reconciliation in progress")
|
||||
return repository
|
||||
|
|
|
@ -100,9 +100,8 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||
}
|
||||
|
||||
// set initial status
|
||||
if repository.Generation != repository.Status.ObservedGeneration ||
|
||||
repository.GetArtifact() != nil && !r.Storage.ArtifactExist(*repository.GetArtifact()) {
|
||||
repository = sourcev1.GitRepositoryProgressing(repository)
|
||||
if resetRepository, ok := r.resetStatus(repository); ok {
|
||||
repository = resetRepository
|
||||
if err := r.Status().Update(ctx, &repository); err != nil {
|
||||
log.Error(err, "unable to update status")
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
|
@ -274,6 +273,20 @@ func (r *GitRepositoryReconciler) verify(ctx context.Context, publicKeySecret ty
|
|||
return nil
|
||||
}
|
||||
|
||||
// resetStatus returns a modified v1alpha1.GitRepository and a boolean indicating
|
||||
// if the status field has been reset.
|
||||
func (r *GitRepositoryReconciler) resetStatus(repository sourcev1.GitRepository) (sourcev1.GitRepository, bool) {
|
||||
if repository.GetArtifact() != nil && !r.Storage.ArtifactExist(*repository.GetArtifact()) {
|
||||
repository = sourcev1.GitRepositoryProgressing(repository)
|
||||
repository.Status.Artifact = nil
|
||||
return repository, true
|
||||
}
|
||||
if repository.Generation != repository.Status.ObservedGeneration {
|
||||
return sourcev1.GitRepositoryProgressing(repository), true
|
||||
}
|
||||
return repository, false
|
||||
}
|
||||
|
||||
// gc performs a garbage collection on all but current artifacts of
|
||||
// the given repository.
|
||||
func (r *GitRepositoryReconciler) gc(repository sourcev1.GitRepository, all bool) error {
|
||||
|
|
|
@ -105,9 +105,8 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
|||
}
|
||||
|
||||
// set initial status
|
||||
if chart.Generation != chart.Status.ObservedGeneration ||
|
||||
chart.GetArtifact() != nil && !r.Storage.ArtifactExist(*chart.GetArtifact()) {
|
||||
chart = sourcev1.HelmChartProgressing(chart)
|
||||
if resetChart, ok := r.resetStatus(chart); ok {
|
||||
chart = resetChart
|
||||
if err := r.Status().Update(ctx, &chart); err != nil {
|
||||
log.Error(err, "unable to update status")
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
|
@ -447,6 +446,20 @@ func (r *HelmChartReconciler) getGitRepositoryWithArtifact(ctx context.Context,
|
|||
return repository, err
|
||||
}
|
||||
|
||||
// resetStatus returns a modified v1alpha1.HelmChart and a boolean indicating
|
||||
// if the status field has been reset.
|
||||
func (r *HelmChartReconciler) resetStatus(chart sourcev1.HelmChart) (sourcev1.HelmChart, bool) {
|
||||
if chart.GetArtifact() != nil && !r.Storage.ArtifactExist(*chart.GetArtifact()) {
|
||||
chart = sourcev1.HelmChartProgressing(chart)
|
||||
chart.Status.Artifact = nil
|
||||
return chart, true
|
||||
}
|
||||
if chart.Generation != chart.Status.ObservedGeneration {
|
||||
return sourcev1.HelmChartProgressing(chart), true
|
||||
}
|
||||
return chart, false
|
||||
}
|
||||
|
||||
// gc performs a garbage collection on all but current artifacts of
|
||||
// the given chart.
|
||||
func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart, all bool) error {
|
||||
|
|
|
@ -260,6 +260,7 @@ var _ = Describe("HelmChartReconciler", func() {
|
|||
}
|
||||
return false
|
||||
}, timeout, interval).Should(BeTrue())
|
||||
Expect(chart.GetArtifact()).NotTo(BeNil())
|
||||
Expect(chart.Status.Artifact.Revision).Should(Equal("0.1.1"))
|
||||
})
|
||||
|
||||
|
|
|
@ -105,9 +105,8 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
|
|||
}
|
||||
|
||||
// set initial status
|
||||
if repository.Generation != repository.Status.ObservedGeneration ||
|
||||
repository.GetArtifact() != nil && !r.Storage.ArtifactExist(*repository.GetArtifact()) {
|
||||
repository = sourcev1.HelmRepositoryProgressing(repository)
|
||||
if resetRepository, ok := r.resetStatus(repository); ok {
|
||||
repository = resetRepository
|
||||
if err := r.Status().Update(ctx, &repository); err != nil {
|
||||
log.Error(err, "unable to update status")
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
|
@ -266,6 +265,20 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
|
|||
return sourcev1.HelmRepositoryReady(repository, artifact, indexURL, sourcev1.IndexationSucceededReason, message), nil
|
||||
}
|
||||
|
||||
// resetStatus returns a modified v1alpha1.HelmRepository and a boolean indicating
|
||||
// if the status field has been reset.
|
||||
func (r *HelmRepositoryReconciler) resetStatus(repository sourcev1.HelmRepository) (sourcev1.HelmRepository, bool) {
|
||||
if repository.GetArtifact() != nil && !r.Storage.ArtifactExist(*repository.GetArtifact()) {
|
||||
repository = sourcev1.HelmRepositoryProgressing(repository)
|
||||
repository.Status.Artifact = nil
|
||||
return repository, true
|
||||
}
|
||||
if repository.Generation != repository.Status.ObservedGeneration {
|
||||
return sourcev1.HelmRepositoryProgressing(repository), true
|
||||
}
|
||||
return repository, false
|
||||
}
|
||||
|
||||
// gc performs a garbage collection on all but current artifacts of
|
||||
// the given repository.
|
||||
func (r *HelmRepositoryReconciler) gc(repository sourcev1.HelmRepository, all bool) error {
|
||||
|
|
Loading…
Reference in New Issue