There isn't actually an "API" between pkg/sdn/plugin and the rest of
OpenShift; the code that starts the master/node/proxy needs to import
pkg/sdn/plugin directly anyway, so just drop the api subdir.
OTOH, IsOpenShiftNetworkPlugin() and some of our defined constants are
used by code that doesn't need access to the internals of the plugin,
so move them out to pkg/sdn/api, and update a few places that were
redefining the names themselves.
| ... | ... |
@@ -41,7 +41,7 @@ func NewCmdIsolateProjectsNetwork(commandName, fullName string, f *clientcmd.Fac |
| 41 | 41 |
cmd := &cobra.Command{
|
| 42 | 42 |
Use: commandName, |
| 43 | 43 |
Short: "Isolate project network", |
| 44 |
- Long: fmt.Sprintf(isolateProjectsNetworkLong, ovsPluginName), |
|
| 44 |
+ Long: fmt.Sprintf(isolateProjectsNetworkLong, sdnapi.MultiTenantPluginName), |
|
| 45 | 45 |
Example: fmt.Sprintf(isolateProjectsNetworkExample, fullName), |
| 46 | 46 |
Run: func(c *cobra.Command, args []string) {
|
| 47 | 47 |
if err := opts.Complete(f, c, args, out); err != nil {
|
| ... | ... |
@@ -45,7 +45,7 @@ func NewCmdJoinProjectsNetwork(commandName, fullName string, f *clientcmd.Factor |
| 45 | 45 |
cmd := &cobra.Command{
|
| 46 | 46 |
Use: commandName, |
| 47 | 47 |
Short: "Join project network", |
| 48 |
- Long: fmt.Sprintf(joinProjectsNetworkLong, ovsPluginName), |
|
| 48 |
+ Long: fmt.Sprintf(joinProjectsNetworkLong, sdnapi.MultiTenantPluginName), |
|
| 49 | 49 |
Example: fmt.Sprintf(joinProjectsNetworkExample, fullName), |
| 50 | 50 |
Run: func(c *cobra.Command, args []string) {
|
| 51 | 51 |
if err := opts.Complete(f, c, args, out); err != nil {
|
| ... | ... |
@@ -42,7 +42,7 @@ func NewCmdMakeGlobalProjectsNetwork(commandName, fullName string, f *clientcmd. |
| 42 | 42 |
cmd := &cobra.Command{
|
| 43 | 43 |
Use: commandName, |
| 44 | 44 |
Short: "Make project network global", |
| 45 |
- Long: fmt.Sprintf(makeGlobalProjectsNetworkLong, ovsPluginName), |
|
| 45 |
+ Long: fmt.Sprintf(makeGlobalProjectsNetworkLong, sdnapi.MultiTenantPluginName), |
|
| 46 | 46 |
Example: fmt.Sprintf(makeGlobalProjectsNetworkExample, fullName), |
| 47 | 47 |
Run: func(c *cobra.Command, args []string) {
|
| 48 | 48 |
if err := opts.Complete(f, c, args, out); err != nil {
|
| ... | ... |
@@ -479,11 +479,11 @@ func (c *NodeConfig) RunProxy() {
|
| 479 | 479 |
|
| 480 | 480 |
endpointsConfig := pconfig.NewEndpointsConfig() |
| 481 | 481 |
// customized handling registration that inserts a filter if needed |
| 482 |
- if c.FilteringEndpointsHandler != nil {
|
|
| 483 |
- if err := c.FilteringEndpointsHandler.Start(endpointsHandler); err != nil {
|
|
| 482 |
+ if c.SDNProxy != nil {
|
|
| 483 |
+ if err := c.SDNProxy.Start(endpointsHandler); err != nil {
|
|
| 484 | 484 |
glog.Fatalf("error: node proxy plugin startup failed: %v", err)
|
| 485 | 485 |
} |
| 486 |
- endpointsHandler = c.FilteringEndpointsHandler |
|
| 486 |
+ endpointsHandler = c.SDNProxy |
|
| 487 | 487 |
} |
| 488 | 488 |
endpointsConfig.RegisterHandler(endpointsHandler) |
| 489 | 489 |
|
| ... | ... |
@@ -36,7 +36,6 @@ import ( |
| 36 | 36 |
"github.com/openshift/origin/pkg/dns" |
| 37 | 37 |
sdnapi "github.com/openshift/origin/pkg/sdn/api" |
| 38 | 38 |
sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
| 39 |
- sdnpluginapi "github.com/openshift/origin/pkg/sdn/plugin/api" |
|
| 40 | 39 |
) |
| 41 | 40 |
|
| 42 | 41 |
// NodeConfig represents the required parameters to start the OpenShift node |
| ... | ... |
@@ -77,9 +76,9 @@ type NodeConfig struct {
|
| 77 | 77 |
DNSServer *dns.Server |
| 78 | 78 |
|
| 79 | 79 |
// SDNPlugin is an optional SDN plugin |
| 80 |
- SDNPlugin sdnpluginapi.OsdnNodePlugin |
|
| 81 |
- // EndpointsFilterer is an optional endpoints filterer |
|
| 82 |
- FilteringEndpointsHandler sdnpluginapi.FilteringEndpointsConfigHandler |
|
| 80 |
+ SDNPlugin *sdnplugin.OsdnNode |
|
| 81 |
+ // SDNProxy is an optional service endpoints filterer |
|
| 82 |
+ SDNProxy *sdnplugin.OsdnProxy |
|
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 | 85 |
func BuildKubernetesNodeConfig(options configapi.NodeConfig, enableProxy, enableDNS bool) (*NodeConfig, error) {
|
| ... | ... |
@@ -166,7 +165,7 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig, enableProxy, enable |
| 166 | 166 |
} |
| 167 | 167 |
server.DockerExecHandlerName = string(options.DockerConfig.ExecHandlerName) |
| 168 | 168 |
|
| 169 |
- if sdnplugin.IsOpenShiftNetworkPlugin(server.NetworkPluginName) {
|
|
| 169 |
+ if sdnapi.IsOpenShiftNetworkPlugin(server.NetworkPluginName) {
|
|
| 170 | 170 |
// set defaults for openshift-sdn |
| 171 | 171 |
server.HairpinMode = componentconfig.HairpinNone |
| 172 | 172 |
server.ConfigureCBR0 = false |
| ... | ... |
@@ -263,7 +262,7 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig, enableProxy, enable |
| 263 | 263 |
deps.NetworkPlugins = append(deps.NetworkPlugins, sdnPlugin) |
| 264 | 264 |
} |
| 265 | 265 |
|
| 266 |
- endpointFilter, err := sdnplugin.NewProxyPlugin(options.NetworkConfig.NetworkPluginName, originClient, kubeClient) |
|
| 266 |
+ sdnProxy, err := sdnplugin.NewProxyPlugin(options.NetworkConfig.NetworkPluginName, originClient, kubeClient) |
|
| 267 | 267 |
if err != nil {
|
| 268 | 268 |
return nil, fmt.Errorf("SDN proxy initialization failed: %v", err)
|
| 269 | 269 |
} |
| ... | ... |
@@ -286,8 +285,8 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig, enableProxy, enable |
| 286 | 286 |
ProxyConfig: proxyconfig, |
| 287 | 287 |
EnableUnidling: options.EnableUnidling, |
| 288 | 288 |
|
| 289 |
- SDNPlugin: sdnPlugin, |
|
| 290 |
- FilteringEndpointsHandler: endpointFilter, |
|
| 289 |
+ SDNPlugin: sdnPlugin, |
|
| 290 |
+ SDNProxy: sdnProxy, |
|
| 291 | 291 |
} |
| 292 | 292 |
|
| 293 | 293 |
if enableDNS {
|
| ... | ... |
@@ -394,7 +393,7 @@ func buildKubeProxyConfig(options configapi.NodeConfig) (*proxyoptions.ProxyServ |
| 394 | 394 |
} |
| 395 | 395 |
|
| 396 | 396 |
func validateNetworkPluginName(originClient *osclient.Client, pluginName string) error {
|
| 397 |
- if sdnplugin.IsOpenShiftNetworkPlugin(pluginName) {
|
|
| 397 |
+ if sdnapi.IsOpenShiftNetworkPlugin(pluginName) {
|
|
| 398 | 398 |
// Detect any plugin mismatches between node and master |
| 399 | 399 |
clusterNetwork, err := originClient.ClusterNetwork().Get(sdnapi.ClusterNetworkDefault) |
| 400 | 400 |
if kerrs.IsNotFound(err) {
|
| ... | ... |
@@ -23,7 +23,7 @@ import ( |
| 23 | 23 |
cmdutil "github.com/openshift/origin/pkg/cmd/util" |
| 24 | 24 |
"github.com/openshift/origin/pkg/cmd/util/docker" |
| 25 | 25 |
utilflags "github.com/openshift/origin/pkg/cmd/util/flags" |
| 26 |
- sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
|
| 26 |
+ sdnapi "github.com/openshift/origin/pkg/sdn/api" |
|
| 27 | 27 |
"github.com/openshift/origin/pkg/version" |
| 28 | 28 |
) |
| 29 | 29 |
|
| ... | ... |
@@ -291,7 +291,7 @@ func StartNode(nodeConfig configapi.NodeConfig, components *utilflags.ComponentF |
| 291 | 291 |
return err |
| 292 | 292 |
} |
| 293 | 293 |
|
| 294 |
- if sdnplugin.IsOpenShiftNetworkPlugin(config.KubeletServer.NetworkPluginName) {
|
|
| 294 |
+ if sdnapi.IsOpenShiftNetworkPlugin(config.KubeletServer.NetworkPluginName) {
|
|
| 295 | 295 |
// TODO: SDN plugin depends on the Kubelet registering as a Node and doesn't retry cleanly, |
| 296 | 296 |
// and Kubelet also can't start the PodSync loop until the SDN plugin has loaded. |
| 297 | 297 |
if components.Enabled(ComponentKubelet) != components.Enabled(ComponentPlugins) {
|
| ... | ... |
@@ -14,6 +14,8 @@ import ( |
| 14 | 14 |
osclient "github.com/openshift/origin/pkg/client" |
| 15 | 15 |
configapilatest "github.com/openshift/origin/pkg/cmd/server/api/latest" |
| 16 | 16 |
"github.com/openshift/origin/pkg/diagnostics/types" |
| 17 |
+ |
|
| 18 |
+ sdnapi "github.com/openshift/origin/pkg/sdn/api" |
|
| 17 | 19 |
) |
| 18 | 20 |
|
| 19 | 21 |
const masterNotRunningAsANode = `Unable to find a node matching the cluster server IP. |
| ... | ... |
@@ -21,9 +23,6 @@ This may indicate the master is not also running a node, and is unable |
| 21 | 21 |
to proxy to pods over the Open vSwitch SDN. |
| 22 | 22 |
` |
| 23 | 23 |
|
| 24 |
-const ovsSubnetPluginName = "redhat/openshift-ovs-subnet" |
|
| 25 |
-const ovsMultiTenantPluginName = "redhat/openshift-ovs-multitenant" |
|
| 26 |
- |
|
| 27 | 24 |
// MasterNode is a Diagnostic for checking that the OpenShift master is also running as node. |
| 28 | 25 |
// This is currently required to have the master on the Open vSwitch SDN and able to communicate |
| 29 | 26 |
// with other nodes. |
| ... | ... |
@@ -62,18 +61,8 @@ func (d *MasterNode) CanRun() (bool, error) {
|
| 62 | 62 |
return false, types.DiagnosticError{ID: "DClu3008",
|
| 63 | 63 |
LogMessage: fmt.Sprintf("Master config provided but unable to parse: %s", masterErr), Cause: masterErr}
|
| 64 | 64 |
} |
| 65 |
- networkPluginName := masterCfg.NetworkConfig.NetworkPluginName |
|
| 66 |
- |
|
| 67 |
- // Make sure this is an OVS network plugin: |
|
| 68 |
- ovsNetworkPlugins := [2]string{ovsSubnetPluginName, ovsMultiTenantPluginName}
|
|
| 69 |
- usingOvsNetworkPlugin := false |
|
| 70 |
- for _, plugin := range ovsNetworkPlugins {
|
|
| 71 |
- if plugin == networkPluginName {
|
|
| 72 |
- usingOvsNetworkPlugin = true |
|
| 73 |
- } |
|
| 74 |
- } |
|
| 75 |
- if !usingOvsNetworkPlugin {
|
|
| 76 |
- return false, errors.New(fmt.Sprintf("Network plugin does not require master to also run node: %s", networkPluginName))
|
|
| 65 |
+ if !sdnapi.IsOpenShiftNetworkPlugin(masterCfg.NetworkConfig.NetworkPluginName) {
|
|
| 66 |
+ return false, errors.New(fmt.Sprintf("Network plugin does not require master to also run node: %s", masterCfg.NetworkConfig.NetworkPluginName))
|
|
| 77 | 67 |
} |
| 78 | 68 |
} |
| 79 | 69 |
|
| ... | ... |
@@ -17,14 +17,13 @@ import ( |
| 17 | 17 |
"github.com/openshift/origin/pkg/diagnostics/networkpod/util" |
| 18 | 18 |
diagutil "github.com/openshift/origin/pkg/diagnostics/util" |
| 19 | 19 |
sdnapi "github.com/openshift/origin/pkg/sdn/api" |
| 20 |
- sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
|
| 21 | 20 |
) |
| 22 | 21 |
|
| 23 | 22 |
func (d *NetworkDiagnostic) TestSetup() error {
|
| 24 | 23 |
d.nsName = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagNamespacePrefix))
|
| 25 | 24 |
|
| 26 | 25 |
nsList := []string{d.nsName}
|
| 27 |
- if sdnplugin.IsOpenShiftMultitenantNetworkPlugin(d.pluginName) {
|
|
| 26 |
+ if sdnapi.IsOpenShiftMultitenantNetworkPlugin(d.pluginName) {
|
|
| 28 | 27 |
d.globalnsName = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagGlobalNamespacePrefix))
|
| 29 | 28 |
nsList = append(nsList, d.globalnsName) |
| 30 | 29 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
osclient "github.com/openshift/origin/pkg/client" |
| 14 | 14 |
"github.com/openshift/origin/pkg/diagnostics/networkpod/util" |
| 15 | 15 |
"github.com/openshift/origin/pkg/diagnostics/types" |
| 16 |
- sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
|
| 16 |
+ sdnapi "github.com/openshift/origin/pkg/sdn/api" |
|
| 17 | 17 |
) |
| 18 | 18 |
|
| 19 | 19 |
const ( |
| ... | ... |
@@ -69,7 +69,7 @@ func (d CheckPodNetwork) Check() types.DiagnosticResult {
|
| 69 | 69 |
return d.res |
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 |
- if sdnplugin.IsOpenShiftMultitenantNetworkPlugin(pluginName) {
|
|
| 72 |
+ if sdnapi.IsOpenShiftMultitenantNetworkPlugin(pluginName) {
|
|
| 73 | 73 |
netnsList, err := d.OSClient.NetNamespaces().List(kapi.ListOptions{})
|
| 74 | 74 |
if err != nil {
|
| 75 | 75 |
d.res.Error("DPodNet1004", err, fmt.Sprintf("Getting all network namespaces failed. Error: %s", err))
|
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
osclient "github.com/openshift/origin/pkg/client" |
| 14 | 14 |
"github.com/openshift/origin/pkg/diagnostics/networkpod/util" |
| 15 | 15 |
"github.com/openshift/origin/pkg/diagnostics/types" |
| 16 |
- sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
|
| 16 |
+ sdnapi "github.com/openshift/origin/pkg/sdn/api" |
|
| 17 | 17 |
) |
| 18 | 18 |
|
| 19 | 19 |
const ( |
| ... | ... |
@@ -79,7 +79,7 @@ func (d CheckServiceNetwork) Check() types.DiagnosticResult {
|
| 79 | 79 |
return d.res |
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 |
- if sdnplugin.IsOpenShiftMultitenantNetworkPlugin(pluginName) {
|
|
| 82 |
+ if sdnapi.IsOpenShiftMultitenantNetworkPlugin(pluginName) {
|
|
| 83 | 83 |
netnsList, err := d.OSClient.NetNamespaces().List(kapi.ListOptions{})
|
| 84 | 84 |
if err != nil {
|
| 85 | 85 |
d.res.Error("DSvcNet1006", err, fmt.Sprintf("Getting all network namespaces failed. Error: %s", err))
|
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
osclient "github.com/openshift/origin/pkg/client" |
| 14 | 14 |
osclientcmd "github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 15 | 15 |
"github.com/openshift/origin/pkg/sdn/api" |
| 16 |
- sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
|
| 16 |
+ sdnapi "github.com/openshift/origin/pkg/sdn/api" |
|
| 17 | 17 |
"github.com/openshift/origin/pkg/util/netutils" |
| 18 | 18 |
) |
| 19 | 19 |
|
| ... | ... |
@@ -41,7 +41,7 @@ func GetOpenShiftNetworkPlugin(osClient *osclient.Client) (string, bool, error) |
| 41 | 41 |
} |
| 42 | 42 |
return "", false, err |
| 43 | 43 |
} |
| 44 |
- return cn.PluginName, sdnplugin.IsOpenShiftNetworkPlugin(cn.PluginName), nil |
|
| 44 |
+ return cn.PluginName, sdnapi.IsOpenShiftNetworkPlugin(cn.PluginName), nil |
|
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 | 47 |
func GetNodes(kubeClient *kclient.Client) ([]kapi.Node, error) {
|
| 48 | 48 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,30 @@ |
| 0 |
+package api |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "strings" |
|
| 4 |
+) |
|
| 5 |
+ |
|
| 6 |
+const ( |
|
| 7 |
+ SingleTenantPluginName = "redhat/openshift-ovs-subnet" |
|
| 8 |
+ MultiTenantPluginName = "redhat/openshift-ovs-multitenant" |
|
| 9 |
+ |
|
| 10 |
+ IngressBandwidthAnnotation = "kubernetes.io/ingress-bandwidth" |
|
| 11 |
+ EgressBandwidthAnnotation = "kubernetes.io/egress-bandwidth" |
|
| 12 |
+ AssignMacvlanAnnotation = "pod.network.openshift.io/assign-macvlan" |
|
| 13 |
+ AssignHostSubnetAnnotation = "pod.network.openshift.io/assign-subnet" |
|
| 14 |
+) |
|
| 15 |
+ |
|
| 16 |
+func IsOpenShiftNetworkPlugin(pluginName string) bool {
|
|
| 17 |
+ switch strings.ToLower(pluginName) {
|
|
| 18 |
+ case SingleTenantPluginName, MultiTenantPluginName: |
|
| 19 |
+ return true |
|
| 20 |
+ } |
|
| 21 |
+ return false |
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+func IsOpenShiftMultitenantNetworkPlugin(pluginName string) bool {
|
|
| 25 |
+ if strings.ToLower(pluginName) == MultiTenantPluginName {
|
|
| 26 |
+ return true |
|
| 27 |
+ } |
|
| 28 |
+ return false |
|
| 29 |
+} |
| ... | ... |
@@ -8,7 +8,6 @@ import ( |
| 8 | 8 |
|
| 9 | 9 |
oapi "github.com/openshift/origin/pkg/api" |
| 10 | 10 |
sdnapi "github.com/openshift/origin/pkg/sdn/api" |
| 11 |
- sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
|
| 12 | 11 |
) |
| 13 | 12 |
|
| 14 | 13 |
// ValidateClusterNetwork tests if required fields in the ClusterNetwork are set. |
| ... | ... |
@@ -88,7 +87,7 @@ func ValidateHostSubnet(hs *sdnapi.HostSubnet) field.ErrorList {
|
| 88 | 88 |
|
| 89 | 89 |
if hs.Subnet == "" {
|
| 90 | 90 |
// check if annotation exists, then let the Subnet field be empty |
| 91 |
- if _, ok := hs.Annotations[sdnplugin.AssignHostSubnetAnnotation]; !ok {
|
|
| 91 |
+ if _, ok := hs.Annotations[sdnapi.AssignHostSubnetAnnotation]; !ok {
|
|
| 92 | 92 |
allErrs = append(allErrs, field.Invalid(field.NewPath("subnet"), hs.Subnet, "Field cannot be empty"))
|
| 93 | 93 |
} |
| 94 | 94 |
} else {
|
| 95 | 95 |
deleted file mode 100644 |
| ... | ... |
@@ -1,17 +0,0 @@ |
| 1 |
-package api |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- knetwork "k8s.io/kubernetes/pkg/kubelet/network" |
|
| 5 |
- pconfig "k8s.io/kubernetes/pkg/proxy/config" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 |
-type OsdnNodePlugin interface {
|
|
| 9 |
- knetwork.NetworkPlugin |
|
| 10 |
- |
|
| 11 |
- Start() error |
|
| 12 |
-} |
|
| 13 |
- |
|
| 14 |
-type FilteringEndpointsConfigHandler interface {
|
|
| 15 |
- pconfig.EndpointsConfigHandler |
|
| 16 |
- Start(baseHandler pconfig.EndpointsConfigHandler) error |
|
| 17 |
-} |
| ... | ... |
@@ -26,7 +26,7 @@ type OsdnMaster struct {
|
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 | 28 |
func StartMaster(networkConfig osconfigapi.MasterNetworkConfig, osClient *osclient.Client, kClient *kclient.Client) error {
|
| 29 |
- if !IsOpenShiftNetworkPlugin(networkConfig.NetworkPluginName) {
|
|
| 29 |
+ if !osapi.IsOpenShiftNetworkPlugin(networkConfig.NetworkPluginName) {
|
|
| 30 | 30 |
return nil |
| 31 | 31 |
} |
| 32 | 32 |
|
| ... | ... |
@@ -92,7 +92,7 @@ func StartMaster(networkConfig osconfigapi.MasterNetworkConfig, osClient *osclie |
| 92 | 92 |
return err |
| 93 | 93 |
} |
| 94 | 94 |
|
| 95 |
- if IsOpenShiftMultitenantNetworkPlugin(networkConfig.NetworkPluginName) {
|
|
| 95 |
+ if osapi.IsOpenShiftMultitenantNetworkPlugin(networkConfig.NetworkPluginName) {
|
|
| 96 | 96 |
master.vnids = newMasterVNIDMap() |
| 97 | 97 |
|
| 98 | 98 |
if err = master.VnidStartMaster(); err != nil {
|
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
|
| 11 | 11 |
osclient "github.com/openshift/origin/pkg/client" |
| 12 | 12 |
osapi "github.com/openshift/origin/pkg/sdn/api" |
| 13 |
- "github.com/openshift/origin/pkg/sdn/plugin/api" |
|
| 14 | 13 |
"github.com/openshift/origin/pkg/util/netutils" |
| 15 | 14 |
"github.com/openshift/origin/pkg/util/ovs" |
| 16 | 15 |
|
| ... | ... |
@@ -39,8 +38,8 @@ type OsdnNode struct {
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
// Called by higher layers to create the plugin SDN node instance |
| 42 |
-func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclient.Client, hostname string, selfIP string, iptablesSyncPeriod time.Duration, mtu uint32) (api.OsdnNodePlugin, error) {
|
|
| 43 |
- if !IsOpenShiftNetworkPlugin(pluginName) {
|
|
| 42 |
+func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclient.Client, hostname string, selfIP string, iptablesSyncPeriod time.Duration, mtu uint32) (*OsdnNode, error) {
|
|
| 43 |
+ if !osapi.IsOpenShiftNetworkPlugin(pluginName) {
|
|
| 44 | 44 |
return nil, nil |
| 45 | 45 |
} |
| 46 | 46 |
|
| ... | ... |
@@ -74,7 +73,7 @@ func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclien |
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 | 76 |
plugin := &OsdnNode{
|
| 77 |
- multitenant: IsOpenShiftMultitenantNetworkPlugin(pluginName), |
|
| 77 |
+ multitenant: osapi.IsOpenShiftMultitenantNetworkPlugin(pluginName), |
|
| 78 | 78 |
kClient: kClient, |
| 79 | 79 |
osClient: osClient, |
| 80 | 80 |
ovs: ovsif, |
| ... | ... |
@@ -8,6 +8,8 @@ import ( |
| 8 | 8 |
|
| 9 | 9 |
"github.com/golang/glog" |
| 10 | 10 |
|
| 11 |
+ osapi "github.com/openshift/origin/pkg/sdn/api" |
|
| 12 |
+ |
|
| 11 | 13 |
kapi "k8s.io/kubernetes/pkg/api" |
| 12 | 14 |
"k8s.io/kubernetes/pkg/api/resource" |
| 13 | 15 |
"k8s.io/kubernetes/pkg/apis/componentconfig" |
| ... | ... |
@@ -19,33 +21,6 @@ import ( |
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 | 21 |
const ( |
| 22 |
- SingleTenantPluginName string = "redhat/openshift-ovs-subnet" |
|
| 23 |
- MultiTenantPluginName string = "redhat/openshift-ovs-multitenant" |
|
| 24 |
- |
|
| 25 |
- IngressBandwidthAnnotation string = "kubernetes.io/ingress-bandwidth" |
|
| 26 |
- EgressBandwidthAnnotation string = "kubernetes.io/egress-bandwidth" |
|
| 27 |
- AssignMacVlanAnnotation string = "pod.network.openshift.io/assign-macvlan" |
|
| 28 |
- AssignHostSubnetAnnotation string = "pod.network.openshift.io/assign-subnet" |
|
| 29 |
-) |
|
| 30 |
- |
|
| 31 |
-func IsOpenShiftNetworkPlugin(pluginName string) bool {
|
|
| 32 |
- switch strings.ToLower(pluginName) {
|
|
| 33 |
- case SingleTenantPluginName, MultiTenantPluginName: |
|
| 34 |
- return true |
|
| 35 |
- } |
|
| 36 |
- return false |
|
| 37 |
-} |
|
| 38 |
- |
|
| 39 |
-func IsOpenShiftMultitenantNetworkPlugin(pluginName string) bool {
|
|
| 40 |
- if strings.ToLower(pluginName) == MultiTenantPluginName {
|
|
| 41 |
- return true |
|
| 42 |
- } |
|
| 43 |
- return false |
|
| 44 |
-} |
|
| 45 |
- |
|
| 46 |
-//----------------------------------------------- |
|
| 47 |
- |
|
| 48 |
-const ( |
|
| 49 | 22 |
setUpCmd = "setup" |
| 50 | 23 |
tearDownCmd = "teardown" |
| 51 | 24 |
statusCmd = "status" |
| ... | ... |
@@ -62,9 +37,9 @@ func (plugin *OsdnNode) Init(host knetwork.Host, _ componentconfig.HairpinMode, |
| 62 | 62 |
|
| 63 | 63 |
func (plugin *OsdnNode) Name() string {
|
| 64 | 64 |
if plugin.multitenant {
|
| 65 |
- return MultiTenantPluginName |
|
| 65 |
+ return osapi.MultiTenantPluginName |
|
| 66 | 66 |
} else {
|
| 67 |
- return SingleTenantPluginName |
|
| 67 |
+ return osapi.SingleTenantPluginName |
|
| 68 | 68 |
} |
| 69 | 69 |
} |
| 70 | 70 |
|
| ... | ... |
@@ -103,14 +78,14 @@ func parseAndValidateBandwidth(value string) (int64, error) {
|
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
func extractBandwidthResources(pod *kapi.Pod) (ingress, egress int64, err error) {
|
| 106 |
- str, found := pod.Annotations[IngressBandwidthAnnotation] |
|
| 106 |
+ str, found := pod.Annotations[osapi.IngressBandwidthAnnotation] |
|
| 107 | 107 |
if found {
|
| 108 | 108 |
ingress, err = parseAndValidateBandwidth(str) |
| 109 | 109 |
if err != nil {
|
| 110 | 110 |
return -1, -1, err |
| 111 | 111 |
} |
| 112 | 112 |
} |
| 113 |
- str, found = pod.Annotations[EgressBandwidthAnnotation] |
|
| 113 |
+ str, found = pod.Annotations[osapi.EgressBandwidthAnnotation] |
|
| 114 | 114 |
if found {
|
| 115 | 115 |
egress, err = parseAndValidateBandwidth(str) |
| 116 | 116 |
if err != nil {
|
| ... | ... |
@@ -121,7 +96,7 @@ func extractBandwidthResources(pod *kapi.Pod) (ingress, egress int64, err error) |
| 121 | 121 |
} |
| 122 | 122 |
|
| 123 | 123 |
func wantsMacvlan(pod *kapi.Pod) (bool, error) {
|
| 124 |
- val, found := pod.Annotations[AssignMacVlanAnnotation] |
|
| 124 |
+ val, found := pod.Annotations[osapi.AssignMacvlanAnnotation] |
|
| 125 | 125 |
if !found || val != "true" {
|
| 126 | 126 |
return false, nil |
| 127 | 127 |
} |
| ... | ... |
@@ -130,7 +105,7 @@ func wantsMacvlan(pod *kapi.Pod) (bool, error) {
|
| 130 | 130 |
return true, nil |
| 131 | 131 |
} |
| 132 | 132 |
} |
| 133 |
- return false, fmt.Errorf("Pod has %q annotation but is not privileged", AssignMacVlanAnnotation)
|
|
| 133 |
+ return false, fmt.Errorf("Pod has %q annotation but is not privileged", osapi.AssignMacvlanAnnotation)
|
|
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 | 136 |
func isScriptError(err error) bool {
|
| ... | ... |
@@ -9,7 +9,6 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
osclient "github.com/openshift/origin/pkg/client" |
| 11 | 11 |
osapi "github.com/openshift/origin/pkg/sdn/api" |
| 12 |
- "github.com/openshift/origin/pkg/sdn/plugin/api" |
|
| 13 | 12 |
|
| 14 | 13 |
kapi "k8s.io/kubernetes/pkg/api" |
| 15 | 14 |
"k8s.io/kubernetes/pkg/client/cache" |
| ... | ... |
@@ -23,7 +22,7 @@ type proxyFirewallItem struct {
|
| 23 | 23 |
net *net.IPNet |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
-type ovsProxyPlugin struct {
|
|
| 26 |
+type OsdnProxy struct {
|
|
| 27 | 27 |
kClient *kclient.Client |
| 28 | 28 |
osClient *osclient.Client |
| 29 | 29 |
networkInfo *NetworkInfo |
| ... | ... |
@@ -35,19 +34,19 @@ type ovsProxyPlugin struct {
|
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 | 37 |
// Called by higher layers to create the proxy plugin instance; only used by nodes |
| 38 |
-func NewProxyPlugin(pluginName string, osClient *osclient.Client, kClient *kclient.Client) (api.FilteringEndpointsConfigHandler, error) {
|
|
| 39 |
- if !IsOpenShiftMultitenantNetworkPlugin(pluginName) {
|
|
| 38 |
+func NewProxyPlugin(pluginName string, osClient *osclient.Client, kClient *kclient.Client) (*OsdnProxy, error) {
|
|
| 39 |
+ if !osapi.IsOpenShiftMultitenantNetworkPlugin(pluginName) {
|
|
| 40 | 40 |
return nil, nil |
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 |
- return &ovsProxyPlugin{
|
|
| 43 |
+ return &OsdnProxy{
|
|
| 44 | 44 |
kClient: kClient, |
| 45 | 45 |
osClient: osClient, |
| 46 | 46 |
firewall: make(map[string][]proxyFirewallItem), |
| 47 | 47 |
}, nil |
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 |
-func (proxy *ovsProxyPlugin) Start(baseHandler pconfig.EndpointsConfigHandler) error {
|
|
| 50 |
+func (proxy *OsdnProxy) Start(baseHandler pconfig.EndpointsConfigHandler) error {
|
|
| 51 | 51 |
glog.Infof("Starting multitenant SDN proxy endpoint filter")
|
| 52 | 52 |
|
| 53 | 53 |
var err error |
| ... | ... |
@@ -69,7 +68,7 @@ func (proxy *ovsProxyPlugin) Start(baseHandler pconfig.EndpointsConfigHandler) e |
| 69 | 69 |
return nil |
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 |
-func (proxy *ovsProxyPlugin) watchEgressNetworkPolicies() {
|
|
| 72 |
+func (proxy *OsdnProxy) watchEgressNetworkPolicies() {
|
|
| 73 | 73 |
RunEventQueue(proxy.osClient, EgressNetworkPolicies, func(delta cache.Delta) error {
|
| 74 | 74 |
policy := delta.Object.(*osapi.EgressNetworkPolicy) |
| 75 | 75 |
if delta.Type == cache.Deleted {
|
| ... | ... |
@@ -88,7 +87,7 @@ func (proxy *ovsProxyPlugin) watchEgressNetworkPolicies() {
|
| 88 | 88 |
}) |
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
-func (proxy *ovsProxyPlugin) updateNetworkPolicy(policy osapi.EgressNetworkPolicy) {
|
|
| 91 |
+func (proxy *OsdnProxy) updateNetworkPolicy(policy osapi.EgressNetworkPolicy) {
|
|
| 92 | 92 |
firewall := make([]proxyFirewallItem, len(policy.Spec.Egress)) |
| 93 | 93 |
for i, rule := range policy.Spec.Egress {
|
| 94 | 94 |
_, cidr, err := net.ParseCIDR(rule.To.CIDRSelector) |
| ... | ... |
@@ -107,7 +106,7 @@ func (proxy *ovsProxyPlugin) updateNetworkPolicy(policy osapi.EgressNetworkPolic |
| 107 | 107 |
} |
| 108 | 108 |
} |
| 109 | 109 |
|
| 110 |
-func (proxy *ovsProxyPlugin) firewallBlocksIP(namespace string, ip net.IP) bool {
|
|
| 110 |
+func (proxy *OsdnProxy) firewallBlocksIP(namespace string, ip net.IP) bool {
|
|
| 111 | 111 |
for _, item := range proxy.firewall[namespace] {
|
| 112 | 112 |
if item.net.Contains(ip) {
|
| 113 | 113 |
return item.policy == osapi.EgressNetworkPolicyRuleDeny |
| ... | ... |
@@ -116,14 +115,14 @@ func (proxy *ovsProxyPlugin) firewallBlocksIP(namespace string, ip net.IP) bool |
| 116 | 116 |
return false |
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 |
-func (proxy *ovsProxyPlugin) OnEndpointsUpdate(allEndpoints []kapi.Endpoints) {
|
|
| 119 |
+func (proxy *OsdnProxy) OnEndpointsUpdate(allEndpoints []kapi.Endpoints) {
|
|
| 120 | 120 |
proxy.lock.Lock() |
| 121 | 121 |
defer proxy.lock.Unlock() |
| 122 | 122 |
proxy.allEndpoints = allEndpoints |
| 123 | 123 |
proxy.updateEndpoints() |
| 124 | 124 |
} |
| 125 | 125 |
|
| 126 |
-func (proxy *ovsProxyPlugin) updateEndpoints() {
|
|
| 126 |
+func (proxy *OsdnProxy) updateEndpoints() {
|
|
| 127 | 127 |
if len(proxy.firewall) == 0 {
|
| 128 | 128 |
proxy.baseEndpointsHandler.OnEndpointsUpdate(proxy.allEndpoints) |
| 129 | 129 |
return |
| ... | ... |
@@ -213,7 +213,7 @@ func (master *OsdnMaster) watchSubnets() {
|
| 213 | 213 |
log.V(5).Infof("Watch %s event for HostSubnet %q", delta.Type, hs.ObjectMeta.Name)
|
| 214 | 214 |
switch delta.Type {
|
| 215 | 215 |
case cache.Sync, cache.Added, cache.Updated: |
| 216 |
- if _, ok := hs.Annotations[AssignHostSubnetAnnotation]; ok {
|
|
| 216 |
+ if _, ok := hs.Annotations[osapi.AssignHostSubnetAnnotation]; ok {
|
|
| 217 | 217 |
// Delete the annotated hostsubnet and create a new one with an assigned subnet |
| 218 | 218 |
// We do not update (instead of delete+create) because the watchSubnets on the nodes |
| 219 | 219 |
// will skip the event if it finds that the hostsubnet has the same host |
| ... | ... |
@@ -11,7 +11,6 @@ import ( |
| 11 | 11 |
|
| 12 | 12 |
osclient "github.com/openshift/origin/pkg/client" |
| 13 | 13 |
sdnapi "github.com/openshift/origin/pkg/sdn/api" |
| 14 |
- sdnplugin "github.com/openshift/origin/pkg/sdn/plugin" |
|
| 15 | 14 |
testutil "github.com/openshift/origin/test/util" |
| 16 | 15 |
testserver "github.com/openshift/origin/test/util/server" |
| 17 | 16 |
) |
| ... | ... |
@@ -81,7 +80,7 @@ func TestOadmPodNetwork(t *testing.T) {
|
| 81 | 81 |
if err != nil {
|
| 82 | 82 |
t.Fatalf("error creating config: %v", err)
|
| 83 | 83 |
} |
| 84 |
- masterConfig.NetworkConfig.NetworkPluginName = sdnplugin.MultiTenantPluginName |
|
| 84 |
+ masterConfig.NetworkConfig.NetworkPluginName = sdnapi.MultiTenantPluginName |
|
| 85 | 85 |
kubeConfigFile, err := testserver.StartConfiguredMaster(masterConfig) |
| 86 | 86 |
if err != nil {
|
| 87 | 87 |
t.Fatalf("error starting server: %v", err)
|