-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement operating modes for the CSI driver
- Loading branch information
Showing
22 changed files
with
833 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/kubernetes-sigs/aws-ebs-csi-driver/cmd/options" | ||
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver" | ||
|
||
"k8s.io/klog" | ||
) | ||
|
||
// Options is the combined set of options for all operating modes. | ||
type Options struct { | ||
DriverMode driver.Mode | ||
|
||
*options.ServerOptions | ||
*options.ControllerOptions | ||
*options.NodeOptions | ||
} | ||
|
||
// used for testing | ||
var osExit = os.Exit | ||
|
||
// GetOptions parses the command line options and returns a struct that contains | ||
// the parsed options. | ||
func GetOptions(fs *flag.FlagSet) *Options { | ||
var ( | ||
version = fs.Bool("version", false, "Print the version and exit.") | ||
|
||
args = os.Args[1:] | ||
mode = driver.AllMode | ||
|
||
serverOptions = options.ServerOptions{} | ||
controllerOptions = options.ControllerOptions{} | ||
nodeOptions = options.NodeOptions{} | ||
) | ||
|
||
serverOptions.AddFlags(fs) | ||
klog.InitFlags(fs) | ||
|
||
if len(os.Args) > 1 { | ||
cmd := os.Args[1] | ||
|
||
switch { | ||
case cmd == string(driver.ControllerMode): | ||
controllerOptions.AddFlags(fs) | ||
args = os.Args[2:] | ||
mode = driver.ControllerMode | ||
|
||
case cmd == string(driver.NodeMode): | ||
nodeOptions.AddFlags(fs) | ||
args = os.Args[2:] | ||
mode = driver.NodeMode | ||
|
||
case cmd == string(driver.AllMode): | ||
controllerOptions.AddFlags(fs) | ||
nodeOptions.AddFlags(fs) | ||
args = os.Args[2:] | ||
|
||
case strings.HasPrefix(cmd, "-"): | ||
controllerOptions.AddFlags(fs) | ||
nodeOptions.AddFlags(fs) | ||
args = os.Args[1:] | ||
|
||
default: | ||
fmt.Printf("unknown command: %s: expected %q, %q or %q", cmd, driver.ControllerMode, driver.NodeMode, driver.AllMode) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
if err := fs.Parse(args); err != nil { | ||
panic(err) | ||
} | ||
|
||
if *version { | ||
info, err := driver.GetVersionJSON() | ||
if err != nil { | ||
klog.Fatalln(err) | ||
} | ||
fmt.Println(info) | ||
osExit(0) | ||
} | ||
|
||
return &Options{ | ||
DriverMode: mode, | ||
|
||
ServerOptions: &serverOptions, | ||
ControllerOptions: &controllerOptions, | ||
NodeOptions: &nodeOptions, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package options | ||
|
||
import ( | ||
"flag" | ||
|
||
cliflag "k8s.io/component-base/cli/flag" | ||
) | ||
|
||
// ControllerOptions contains options and configuration settings for the controller service. | ||
type ControllerOptions struct { | ||
// ExtraVolumeTags is a map of tags that will be attached to each dynamically provisioned | ||
// volume. | ||
ExtraVolumeTags map[string]string | ||
} | ||
|
||
func (s *ControllerOptions) AddFlags(fs *flag.FlagSet) { | ||
fs.Var(cliflag.NewMapStringString(&s.ExtraVolumeTags), "extra-volume-tags", "Extra volume tags to attach to each dynamically provisioned volume. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package options | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
) | ||
|
||
func TestControllerOptions(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
flag string | ||
found bool | ||
}{ | ||
{ | ||
name: "lookup desired flag", | ||
flag: "extra-volume-tags", | ||
found: true, | ||
}, | ||
{ | ||
name: "fail for non-desired flag", | ||
flag: "some-other-flag", | ||
found: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
flagSet := flag.NewFlagSet("test-flagset", flag.ContinueOnError) | ||
controllerOptions := &ControllerOptions{} | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
controllerOptions.AddFlags(flagSet) | ||
|
||
flag := flagSet.Lookup(tc.flag) | ||
found := flag != nil | ||
if found != tc.found { | ||
t.Fatalf("result not equal\ngot:\n%v\nexpected:\n%v", found, tc.found) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package options | ||
|
||
import ( | ||
"flag" | ||
) | ||
|
||
// NodeOptions contains options and configuration settings for the node service. | ||
type NodeOptions struct{} | ||
|
||
func (s *NodeOptions) AddFlags(fs *flag.FlagSet) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package options | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
) | ||
|
||
func TestNodeOptions(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
flag string | ||
found bool | ||
}{ | ||
{ | ||
name: "fail for non-desired flag", | ||
flag: "some-flag", | ||
found: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
flagSet := flag.NewFlagSet("test-flagset", flag.ContinueOnError) | ||
nodeOptions := &NodeOptions{} | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
nodeOptions.AddFlags(flagSet) | ||
|
||
flag := flagSet.Lookup(tc.flag) | ||
found := flag != nil | ||
if found != tc.found { | ||
t.Fatalf("result not equal\ngot:\n%v\nexpected:\n%v", found, tc.found) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.