Skip to content

Commit cabb9ee

Browse files
If accessgrant is received with out redemptionsallowed specified (skupperproject#2198)
we will default the value to 1. This will allow the accessgrant to be functional.
1 parent 3889fb8 commit cabb9ee

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

internal/kube/grants/grant_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func TestGrantRegistryGeneral(t *testing.T) {
5454
RedemptionsAllowed: 3,
5555
},
5656
},
57+
&v2alpha1.AccessGrant{
58+
ObjectMeta: metav1.ObjectMeta{
59+
Name: "default redemptions",
60+
Namespace: "test",
61+
UID: "74ebd47e-28d9-449b-ac64-df1723cb2133",
62+
},
63+
},
5764
}
5865
var skupperObjects []runtime.Object
5966
for _, grant := range grants {
@@ -70,6 +77,13 @@ func TestGrantRegistryGeneral(t *testing.T) {
7077
if err != nil {
7178
t.Error(err)
7279
}
80+
// if redemptions == 0 first run of checkGrant defaults the value to 1, need to rerun checkGrant to perform other checks
81+
if grant.ObjectMeta.Name == "default redemptions" {
82+
err = registry.checkGrant(key, grant)
83+
if err != nil {
84+
t.Error(err)
85+
}
86+
}
7387
latest, err := client.GetSkupperClient().SkupperV2alpha1().AccessGrants(grant.Namespace).Get(context.TODO(), grant.Name, metav1.GetOptions{})
7488
if err != nil {
7589
t.Error(err)
@@ -85,6 +99,11 @@ func TestGrantRegistryGeneral(t *testing.T) {
8599
if err != nil {
86100
t.Error(err)
87101
}
102+
if grant.Spec.RedemptionsAllowed == 0 {
103+
assert.Equal(t, latest.Spec.RedemptionsAllowed, 1)
104+
} else {
105+
assert.Equal(t, latest.Spec.RedemptionsAllowed, grant.Spec.RedemptionsAllowed)
106+
}
88107
assert.Assert(t, meta.IsStatusConditionTrue(latest.Status.Conditions, v2alpha1.CONDITION_TYPE_PROCESSED))
89108
}
90109
for _, ca := range []string{"dummydataformyCA", "dummydataformyCA", "changedCAdata"} {

internal/kube/grants/grants.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ func (g *Grants) checkGrant(key string, grant *skupperv2alpha1.AccessGrant) erro
175175
g.remove(key)
176176
return nil
177177
}
178+
179+
// if RedemptionsAllowed is not set default to 1 so that grant is usable
180+
if grant.Spec.RedemptionsAllowed == 0 {
181+
grant.Spec.RedemptionsAllowed = 1
182+
_, e := g.clients.GetSkupperClient().SkupperV2alpha1().AccessGrants(grant.ObjectMeta.Namespace).Update(context.TODO(), grant, metav1.UpdateOptions{})
183+
if e != nil {
184+
return fmt.Errorf("%s", fmt.Sprintf("Failed updating Redemptions Allowed %s", e))
185+
} else {
186+
return nil
187+
}
188+
}
189+
178190
g.record(key, grant)
179191
changed := false
180192
var status []string
@@ -210,8 +222,15 @@ func (g *Grants) checkGrant(key string, grant *skupperv2alpha1.AccessGrant) erro
210222
changed = true
211223
}
212224
}
225+
213226
var err error
214227

228+
// if RedemptionsAllowed is not set default to 1 so that grant is usable
229+
if grant.Spec.RedemptionsAllowed == 0 {
230+
grant.Spec.RedemptionsAllowed = 1
231+
changed = true
232+
}
233+
215234
if len(status) != 0 {
216235
err = fmt.Errorf("%s", strings.Join(status, ", "))
217236
}

0 commit comments

Comments
 (0)