@@ -126,8 +126,8 @@ func (ai *CCRAPIClient) GetAllCcrRepo(secret map[string]configs.Secret, ccrRegio
126126 offset := int64 (0 )
127127 limit := int64 (100 )
128128 maxGorutineNum := 5
129- page := toltalCount / limit
130- if toltalCount % limit > 0 {
129+ page := toltalCount / limit
130+ if toltalCount % limit > 0 {
131131 page ++
132132 }
133133 wg := sync.WaitGroup {}
@@ -141,12 +141,12 @@ func (ai *CCRAPIClient) GetAllCcrRepo(secret map[string]configs.Secret, ccrRegio
141141 }
142142 }()
143143
144- for j := int64 (0 );j < page ;j ++ {
144+ for j := int64 (0 ); j < page ; j ++ {
145145 wg .Add (1 )
146146 <- leakCh
147147 go func (n int64 ) {
148148 defer wg .Done ()
149- offset = n * limit
149+ offset = n * limit
150150 resp , err := ai .DescribeRepositoryOwnerPersonal (secretID , secretKey , ccrRegion , offset , limit )
151151 if err != nil {
152152 log .Errorf ("get ccr repo offset %d limit %d error, %s" , offset , limit , err )
@@ -159,14 +159,18 @@ func (ai *CCRAPIClient) GetAllCcrRepo(secret map[string]configs.Secret, ccrRegio
159159 }
160160 }
161161 leakCh <- struct {}{}
162- }(j )
162+ }(j )
163163 }
164164 wg .Wait ()
165165 return nil
166166}
167167
168168// GetRepoTags get ccr repo tags
169- func (ai * CCRAPIClient ) GetRepoTags (secretID , secretKey , ccrRegion , repoName string ) ([]string , error ) {
169+ func (ai * CCRAPIClient ) GetRepoTags (secretID , secretKey , ccrRegion , repoName string , ccrTagNum int64 ) ([]string , error ) {
170+
171+ if ccrTagNum < 0 {
172+ return nil , errors .Errorf ("Invalid value ccrTagNum %v" , ccrTagNum )
173+ }
170174
171175 offset := int64 (0 )
172176 count := int64 (0 )
@@ -189,21 +193,32 @@ func (ai *CCRAPIClient) GetRepoTags(secretID, secretKey, ccrRegion, repoName str
189193 if tagCount == 0 {
190194 return nil , nil
191195 }
196+ if ccrTagNum >= tagCount {
197+ ccrTagNum = tagCount
198+ }
192199
193200 count += int64 (len (resp .Response .Data .TagInfo ))
194201 for _ , tagInfo := range resp .Response .Data .TagInfo {
195202 result = append (result , * tagInfo .TagName )
196203 }
197204
205+ if count >= ccrTagNum {
206+ break
207+ }
208+
198209 if count >= tagCount {
199210 break
200211 } else {
201212 offset += limit
202213 }
203214
204215 }
216+ // in case index out of range
217+ if ccrTagNum > int64 (len (result )) {
218+ ccrTagNum = int64 (len (result ))
219+ }
205220
206- return result , nil
221+ return result [: ccrTagNum ] , nil
207222}
208223
209224func (ai * CCRAPIClient ) DescribeImagePersonal (secretID , secretKey ,
0 commit comments