Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
1a11a188
Commit
1a11a188
authored
Nov 13, 2017
by
stewart-yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using regexp match achieve find efficiently
parent
fd3de96b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
instances.go
pkg/cloudprovider/providers/aws/instances.go
+5
-2
volumes.go
pkg/cloudprovider/providers/aws/volumes.go
+5
-2
No files found.
pkg/cloudprovider/providers/aws/instances.go
View file @
1a11a188
...
@@ -25,10 +25,14 @@ import (
...
@@ -25,10 +25,14 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"regexp"
"sync"
"sync"
"time"
"time"
)
)
// awsInstanceRegMatch represents Regex Match for AWS instance.
var
awsInstanceRegMatch
=
regexp
.
MustCompile
(
"^i-[^/]*$"
)
// awsInstanceID represents the ID of the instance in the AWS API, e.g. i-12345678
// awsInstanceID represents the ID of the instance in the AWS API, e.g. i-12345678
// The "traditional" format is "i-12345678"
// The "traditional" format is "i-12345678"
// A new longer format is also being introduced: "i-12345678abcdef01"
// A new longer format is also being introduced: "i-12345678abcdef01"
...
@@ -76,8 +80,7 @@ func (name kubernetesInstanceID) mapToAWSInstanceID() (awsInstanceID, error) {
...
@@ -76,8 +80,7 @@ func (name kubernetesInstanceID) mapToAWSInstanceID() (awsInstanceID, error) {
// We sanity check the resulting volume; the two known formats are
// We sanity check the resulting volume; the two known formats are
// i-12345678 and i-12345678abcdef01
// i-12345678 and i-12345678abcdef01
// TODO: Regex match?
if
awsID
==
""
||
!
awsInstanceRegMatch
.
MatchString
(
awsID
)
{
if
awsID
==
""
||
strings
.
Contains
(
awsID
,
"/"
)
||
!
strings
.
HasPrefix
(
awsID
,
"i-"
)
{
return
""
,
fmt
.
Errorf
(
"Invalid format for AWS instance (%s)"
,
name
)
return
""
,
fmt
.
Errorf
(
"Invalid format for AWS instance (%s)"
,
name
)
}
}
...
...
pkg/cloudprovider/providers/aws/volumes.go
View file @
1a11a188
...
@@ -19,11 +19,15 @@ package aws
...
@@ -19,11 +19,15 @@ package aws
import
(
import
(
"fmt"
"fmt"
"net/url"
"net/url"
"regexp"
"strings"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws"
)
)
// awsVolumeRegMatch represents Regex Match for AWS volume.
var
awsVolumeRegMatch
=
regexp
.
MustCompile
(
"^vol-[^/]*$"
)
// awsVolumeID represents the ID of the volume in the AWS API, e.g. vol-12345678
// awsVolumeID represents the ID of the volume in the AWS API, e.g. vol-12345678
// The "traditional" format is "vol-12345678"
// The "traditional" format is "vol-12345678"
// A new longer format is also being introduced: "vol-12345678abcdef01"
// A new longer format is also being introduced: "vol-12345678abcdef01"
...
@@ -75,8 +79,7 @@ func (name KubernetesVolumeID) mapToAWSVolumeID() (awsVolumeID, error) {
...
@@ -75,8 +79,7 @@ func (name KubernetesVolumeID) mapToAWSVolumeID() (awsVolumeID, error) {
// We sanity check the resulting volume; the two known formats are
// We sanity check the resulting volume; the two known formats are
// vol-12345678 and vol-12345678abcdef01
// vol-12345678 and vol-12345678abcdef01
// TODO: Regex match?
if
!
awsVolumeRegMatch
.
MatchString
(
awsID
)
{
if
strings
.
Contains
(
awsID
,
"/"
)
||
!
strings
.
HasPrefix
(
awsID
,
"vol-"
)
{
return
""
,
fmt
.
Errorf
(
"Invalid format for AWS volume (%s)"
,
name
)
return
""
,
fmt
.
Errorf
(
"Invalid format for AWS volume (%s)"
,
name
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment