Skip to content

Commit

Permalink
Rename --config-scope-exerimental to --config-mesh-experimental (#26)
Browse files Browse the repository at this point in the history
This also includes a change from a "scope:" prefix in the node ID to a
"mesh:" prefix instead.
  • Loading branch information
gnossen committed Jan 5, 2022
1 parent aa4d3f7 commit d6baaf7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
gkePodName = flag.String("gke-pod-name-experimental", "", "GKE pod name to use, instead of reading it from $HOSTNAME or /etc/hostname file. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
gkeNamespace = flag.String("gke-namespace-experimental", "", "GKE namespace to use. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
gceVM = flag.String("gce-vm-experimental", "", "GCE VM name to use, instead of reading it from the metadata server. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
configScope = flag.String("config-scope-experimental", "", "Scope dictating which application networking configuration to use. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
configMesh = flag.String("config-mesh-experimental", "", "Dictates which Mesh resource to use. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
)

func main() {
Expand Down Expand Up @@ -130,7 +130,7 @@ func main() {
secretsDir: *secretsDir,
metadataLabels: nodeMetadata,
deploymentInfo: deploymentInfo,
configScope: *configScope,
configMesh: *configMesh,
}

if err := validate(input); err != nil {
Expand Down Expand Up @@ -181,13 +181,13 @@ type configInput struct {
secretsDir string
metadataLabels map[string]string
deploymentInfo map[string]string
configScope string
configMesh string
}

func validate(in configInput) error {
re := regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9-]{0,63}$`)
if in.configScope != "" && !re.MatchString(in.configScope) {
return fmt.Errorf("config-scope may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length")
if in.configMesh != "" && !re.MatchString(in.configMesh) {
return fmt.Errorf("config-mesh may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length")
}

return nil
Expand Down Expand Up @@ -224,8 +224,8 @@ func generate(in configInput) ([]byte, error) {
// the metadata field while the v3 implementation expects these in the id
// field.
networkIdentifier := in.vpcNetworkName
if in.configScope != "" {
networkIdentifier = fmt.Sprintf("scope:%s", in.configScope)
if in.configMesh != "" {
networkIdentifier = fmt.Sprintf("mesh:%s", in.configMesh)
}

c.Node.Id = fmt.Sprintf("projects/%d/networks/%s/nodes/%s", in.gcpProjectNumber, networkIdentifier, uuid.New().String())
Expand Down
28 changes: 14 additions & 14 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestValidate(t *testing.T) {
wantError string
}{
{
desc: "fails when config-scope has too many characters",
desc: "fails when config-mesh has too many characters",
input: configInput{
xdsServerUri: "example.com:443",
gcpProjectNumber: 123456789012345,
Expand All @@ -43,12 +43,12 @@ func TestValidate(t *testing.T) {
zone: "uscentral-5",
metadataLabels: map[string]string{"k1": "v1", "k2": "v2"},
includeV3Features: true,
configScope: strings.Repeat("a", 65),
configMesh: strings.Repeat("a", 65),
},
wantError: "config-scope may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length",
wantError: "config-mesh may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length",
},
{
desc: "fails when config-scope does not start with an alphabetic letter",
desc: "fails when config-mesh does not start with an alphabetic letter",
input: configInput{
xdsServerUri: "example.com:443",
gcpProjectNumber: 123456789012345,
Expand All @@ -57,12 +57,12 @@ func TestValidate(t *testing.T) {
zone: "uscentral-5",
metadataLabels: map[string]string{"k1": "v1", "k2": "v2"},
includeV3Features: true,
configScope: "4foo",
configMesh: "4foo",
},
wantError: "config-scope may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length",
wantError: "config-mesh may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length",
},
{
desc: "fails when config-scope contains characters besides letters, numbers, and hyphens.",
desc: "fails when config-mesh contains characters besides letters, numbers, and hyphens.",
input: configInput{
xdsServerUri: "example.com:443",
gcpProjectNumber: 123456789012345,
Expand All @@ -71,9 +71,9 @@ func TestValidate(t *testing.T) {
zone: "uscentral-5",
metadataLabels: map[string]string{"k1": "v1", "k2": "v2"},
includeV3Features: true,
configScope: "h*x8",
configMesh: "h*x8",
},
wantError: "config-scope may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length",
wantError: "config-mesh may only contain letters, numbers, and '-'. It must begin with a letter and must not exceed 64 characters in length",
},
}

Expand Down Expand Up @@ -275,7 +275,7 @@ func TestGenerate(t *testing.T) {
}`,
},
{
desc: "configScope specified",
desc: "configMesh specified",
input: configInput{
xdsServerUri: "example.com:443",
gcpProjectNumber: 123456789012345,
Expand All @@ -291,7 +291,7 @@ func TestGenerate(t *testing.T) {
"INSTANCE-IP": "10.9.8.7",
"GCE-VM": "test-gce-vm",
},
configScope: "testscope",
configMesh: "testmesh",
},
wantOutput: `{
"xds_servers": [
Expand All @@ -308,7 +308,7 @@ func TestGenerate(t *testing.T) {
}
],
"node": {
"id": "projects/123456789012345/networks/scope:testscope/nodes/9566c74d-1003-4c4d-bbbb-0407d1e2c649",
"id": "projects/123456789012345/networks/mesh:testmesh/nodes/9566c74d-1003-4c4d-bbbb-0407d1e2c649",
"cluster": "cluster",
"metadata": {
"INSTANCE_IP": "10.9.8.7",
Expand All @@ -330,15 +330,15 @@ func TestGenerate(t *testing.T) {
}`,
},
{
desc: "configScope specified with v2 config",
desc: "configMesh specified with v2 config",
input: configInput{
xdsServerUri: "example.com:443",
gcpProjectNumber: 123456789012345,
vpcNetworkName: "thedefault",
ip: "10.9.8.7",
zone: "uscentral-5",
includeV3Features: false,
configScope: "testscope",
configMesh: "testmesh",
},
wantOutput: `{
"xds_servers": [
Expand Down

0 comments on commit d6baaf7

Please sign in to comment.