Skip to content

Commit 88299de

Browse files
Merge pull request #1127 from hongkailiu/cleanup
NO-ISSUE: Simplify the preconditions code
2 parents 6e02b08 + c03ae9c commit 88299de

File tree

5 files changed

+9
-17
lines changed

5 files changed

+9
-17
lines changed

pkg/payload/precondition/clusterversion/gianthop.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@ import (
1414

1515
// GiantHop blocks giant hops from the version that is currently being reconciled.
1616
type GiantHop struct {
17-
key string
1817
lister configv1listers.ClusterVersionLister
1918
}
2019

2120
// NewGiantHop returns a new GiantHop precondition check.
2221
func NewGiantHop(lister configv1listers.ClusterVersionLister) *GiantHop {
2322
return &GiantHop{
24-
key: "version",
2523
lister: lister,
2624
}
2725
}
2826

29-
// Name returns Name for the precondition.
27+
// Name returns the name of the precondition.
3028
func (p *GiantHop) Name() string { return "ClusterVersionGiantHop" }
3129

3230
// Run runs the GiantHop precondition, blocking giant hops from the
3331
// version that is currently being reconciled. It returns a
3432
// PreconditionError when possible.
3533
func (p *GiantHop) Run(ctx context.Context, releaseContext precondition.ReleaseContext) error {
36-
cv, err := p.lister.Get(p.key)
34+
cv, err := p.lister.Get("version")
3735
if apierrors.IsNotFound(err) || meta.IsNoMatchError(err) {
3836
return nil
3937
}

pkg/payload/precondition/clusterversion/recommendedupdate.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ import (
1616

1717
// RecommendedUpdate checks if clusterversion is upgradeable currently.
1818
type RecommendedUpdate struct {
19-
key string
2019
lister configv1listers.ClusterVersionLister
2120
}
2221

2322
// NewRecommendedUpdate returns a new RecommendedUpdate precondition check.
2423
func NewRecommendedUpdate(lister configv1listers.ClusterVersionLister) *RecommendedUpdate {
2524
return &RecommendedUpdate{
26-
key: "version",
2725
lister: lister,
2826
}
2927
}
3028

3129
// Run runs the RecommendedUpdate precondition.
3230
// Returns PreconditionError when possible, if the requested target release is Recommended=False.
3331
func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext precondition.ReleaseContext) error {
34-
clusterVersion, err := ru.lister.Get(ru.key)
32+
clusterVersion, err := ru.lister.Get("version")
3533
if apierrors.IsNotFound(err) || meta.IsNoMatchError(err) {
3634
return nil
3735
}
@@ -121,5 +119,5 @@ func (ru *RecommendedUpdate) Run(ctx context.Context, releaseContext preconditio
121119
return nil
122120
}
123121

124-
// Name returns Name for the precondition.
122+
// Name returns the name of the precondition.
125123
func (ru *RecommendedUpdate) Name() string { return "ClusterVersionRecommendedUpdate" }

pkg/payload/precondition/clusterversion/rollback.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,24 @@ import (
1515

1616
// Rollback blocks rollbacks from the version that is currently being reconciled.
1717
type Rollback struct {
18-
key string
1918
lister configv1listers.ClusterVersionLister
2019
}
2120

2221
// NewRollback returns a new Rollback precondition check.
2322
func NewRollback(lister configv1listers.ClusterVersionLister) *Rollback {
2423
return &Rollback{
25-
key: "version",
2624
lister: lister,
2725
}
2826
}
2927

30-
// Name returns Name for the precondition.
28+
// Name returns the name of the precondition.
3129
func (p *Rollback) Name() string { return "ClusterVersionRollback" }
3230

3331
// Run runs the Rollback precondition, blocking rollbacks from the
3432
// version that is currently being reconciled. It returns a
3533
// PreconditionError when possible.
3634
func (p *Rollback) Run(ctx context.Context, releaseContext precondition.ReleaseContext) error {
37-
cv, err := p.lister.Get(p.key)
35+
cv, err := p.lister.Get("version")
3836
if apierrors.IsNotFound(err) || meta.IsNoMatchError(err) {
3937
return nil
4038
}

pkg/payload/precondition/clusterversion/upgradeable.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ import (
1717

1818
// Upgradeable checks if clusterversion is upgradeable currently.
1919
type Upgradeable struct {
20-
key string
2120
lister configv1listers.ClusterVersionLister
2221
}
2322

2423
// NewUpgradeable returns a new Upgradeable precondition check.
2524
func NewUpgradeable(lister configv1listers.ClusterVersionLister) *Upgradeable {
2625
return &Upgradeable{
27-
key: "version",
2826
lister: lister,
2927
}
3028
}
@@ -49,7 +47,7 @@ func ClusterVersionOverridesCondition(cv *configv1.ClusterVersion) *configv1.Clu
4947
// If the feature gate `key` is not found, or the api for clusterversion doesn't exist, this check is inert and always returns nil error.
5048
// Otherwise, if Upgradeable condition is set to false in the object, it returns an PreconditionError when possible.
5149
func (pf *Upgradeable) Run(ctx context.Context, releaseContext precondition.ReleaseContext) error {
52-
cv, err := pf.lister.Get(pf.key)
50+
cv, err := pf.lister.Get("version")
5351
if apierrors.IsNotFound(err) || meta.IsNoMatchError(err) {
5452
return nil
5553
}
@@ -119,5 +117,5 @@ func (pf *Upgradeable) Run(ctx context.Context, releaseContext precondition.Rele
119117
}
120118
}
121119

122-
// Name returns Name for the precondition.
120+
// Name returns the name of the precondition.
123121
func (pf *Upgradeable) Name() string { return "ClusterVersionUpgradeable" }

pkg/payload/precondition/precondition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Precondition interface {
4444
// Run executes the precondition checks ands returns an error when the precondition fails.
4545
Run(ctx context.Context, releaseContext ReleaseContext) error
4646

47-
// Name returns a human friendly name for the precondition.
47+
// Name returns a human friendly name of the precondition.
4848
Name() string
4949
}
5050

0 commit comments

Comments
 (0)