@@ -73,6 +73,7 @@ func NewClaimFactory(clients kube.Clients, namespace string, siteContext SiteCon
7373}
7474
7575func (m * ClaimFactory ) CreateTokenClaim (name string , password []byte , expiry time.Duration , uses int ) (* corev1.Secret , error ) {
76+ var expiryStr string
7677 options , err := checkOptions (name , password , expiry , uses )
7778 if err != nil {
7879 return nil , err
@@ -82,11 +83,15 @@ func (m *ClaimFactory) CreateTokenClaim(name string, password []byte, expiry tim
8283 return nil , fmt .Errorf ("Edge configuration cannot accept connections" )
8384 }
8485
85- claim , err := m .createClaimToken (options .Name , options .Password )
86+ if expiry > 0 {
87+ expiration := time .Now ().Add (expiry )
88+ expiryStr = expiration .Format (time .RFC3339 )
89+ }
90+ claim , err := m .createClaimToken (options .Name , options .Password , expiryStr )
8691 if err != nil {
8792 return nil , err
8893 }
89- err = m .createClaimRecord (options .Name , options .Password , options . Expiry , options .Uses )
94+ err = m .createClaimRecord (options .Name , options .Password , expiryStr , options .Uses )
9095 if err != nil {
9196 return nil , err
9297 }
@@ -95,6 +100,7 @@ func (m *ClaimFactory) CreateTokenClaim(name string, password []byte, expiry tim
95100}
96101
97102func (m * ClaimFactory ) RecreateTokenClaim (name string ) (* corev1.Secret , error ) {
103+ var expiryStr string
98104 secret , err := m .clients .GetKubeClient ().CoreV1 ().Secrets (m .namespace ).Get (m .ctx , name , metav1.GetOptions {})
99105 if errors .IsNotFound (err ) {
100106 return nil , nil
@@ -104,11 +110,14 @@ func (m *ClaimFactory) RecreateTokenClaim(name string) (*corev1.Secret, error) {
104110 return nil , nil
105111 }
106112 password := secret .Data [types .ClaimPasswordDataKey ]
107- token , err := m .createClaimToken (name , password )
113+ if secret .ObjectMeta .Annotations [types .ClaimExpiration ] != "" {
114+ expiryStr = secret .ObjectMeta .Annotations [types .ClaimExpiration ]
115+ }
116+ token , err := m .createClaimToken (name , password , expiryStr )
108117 return token , err
109118}
110119
111- func (m * ClaimFactory ) createClaimRecord (name string , password []byte , expiry time. Duration , uses int ) error {
120+ func (m * ClaimFactory ) createClaimRecord (name string , password []byte , expiry string , uses int ) error {
112121 record := corev1.Secret {
113122 TypeMeta : metav1.TypeMeta {
114123 APIVersion : "v1" ,
@@ -128,9 +137,8 @@ func (m *ClaimFactory) createClaimRecord(name string, password []byte, expiry ti
128137 },
129138 }
130139 record .ObjectMeta .OwnerReferences = m .siteContext .GetOwnerReferences ()
131- if expiry > 0 {
132- expiration := time .Now ().Add (expiry )
133- record .ObjectMeta .Annotations [types .ClaimExpiration ] = expiration .Format (time .RFC3339 )
140+ if expiry != "" {
141+ record .ObjectMeta .Annotations [types .ClaimExpiration ] = expiry
134142 }
135143 if uses > 0 {
136144 record .ObjectMeta .Annotations [types .ClaimsRemaining ] = strconv .Itoa (uses )
@@ -139,7 +147,7 @@ func (m *ClaimFactory) createClaimRecord(name string, password []byte, expiry ti
139147 return err
140148}
141149
142- func (m * ClaimFactory ) createClaimToken (name string , password []byte ) (* corev1.Secret , error ) {
150+ func (m * ClaimFactory ) createClaimToken (name string , password []byte , expiry string ) (* corev1.Secret , error ) {
143151 hostPort , err := m .siteContext .GetHostPortForClaims ()
144152 if err != nil {
145153 return nil , err
@@ -171,6 +179,11 @@ func (m *ClaimFactory) createClaimToken(name string, password []byte) (*corev1.S
171179 types .ClaimCaCertDataKey : caSecret .Data ["tls.crt" ],
172180 },
173181 }
182+ claim .ObjectMeta .OwnerReferences = m .siteContext .GetOwnerReferences ()
183+ if expiry != "" {
184+ claim .ObjectMeta .Annotations [types .ClaimExpiration ] = expiry
185+ }
186+
174187 return & claim , nil
175188}
176189
0 commit comments