mirror of https://github.com/kubernetes/kops.git
add network builder
This commit is contained in:
parent
516daa0ac1
commit
280e775466
|
|
@ -94,6 +94,7 @@ k8s.io/kops/pkg/model/defaults
|
|||
k8s.io/kops/pkg/model/domodel
|
||||
k8s.io/kops/pkg/model/gcemodel
|
||||
k8s.io/kops/pkg/model/iam
|
||||
k8s.io/kops/pkg/model/openstackmodel
|
||||
k8s.io/kops/pkg/model/resources
|
||||
k8s.io/kops/pkg/model/vspheremodel
|
||||
k8s.io/kops/pkg/openapi
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"context.go",
|
||||
"convenience.go",
|
||||
"network.go",
|
||||
],
|
||||
importpath = "k8s.io/kops/pkg/model/openstackmodel",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/model:go_default_library",
|
||||
"//upup/pkg/fi:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/openstacktasks:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
Copyright 2018 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 openstackmodel
|
||||
|
||||
import "k8s.io/kops/pkg/model"
|
||||
|
||||
type OpenstackModelContext struct {
|
||||
*model.KopsModelContext
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Copyright 2018 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 openstackmodel
|
||||
|
||||
import "k8s.io/kops/upup/pkg/fi"
|
||||
|
||||
// s is a helper that builds a *string from a string value
|
||||
func s(v string) *string {
|
||||
return fi.String(v)
|
||||
}
|
||||
|
||||
// i64 is a helper that builds a *int64 from an int64 value
|
||||
func i64(v int64) *int64 {
|
||||
return fi.Int64(v)
|
||||
}
|
||||
|
||||
// i32 is a helper that builds a *int32 from an int32 value
|
||||
func i32(v int32) *int32 {
|
||||
return fi.Int32(v)
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
Copyright 2018 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 openstackmodel
|
||||
|
||||
import (
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/openstacktasks"
|
||||
)
|
||||
|
||||
// NetworkModelBuilder configures network objects
|
||||
type NetworkModelBuilder struct {
|
||||
*OpenstackModelContext
|
||||
Lifecycle *fi.Lifecycle
|
||||
}
|
||||
|
||||
var _ fi.ModelBuilder = &NetworkModelBuilder{}
|
||||
|
||||
func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
|
||||
clusterName := b.ClusterName()
|
||||
|
||||
{
|
||||
t := &openstacktasks.Network{
|
||||
Name: s(clusterName),
|
||||
ID: s(b.Cluster.Spec.NetworkID),
|
||||
Lifecycle: b.Lifecycle,
|
||||
}
|
||||
|
||||
c.AddTask(t)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -44,6 +44,7 @@ go_library(
|
|||
"//pkg/model/components:go_default_library",
|
||||
"//pkg/model/domodel:go_default_library",
|
||||
"//pkg/model/gcemodel:go_default_library",
|
||||
"//pkg/model/openstackmodel:go_default_library",
|
||||
"//pkg/model/vspheremodel:go_default_library",
|
||||
"//pkg/resources/digitalocean:go_default_library",
|
||||
"//pkg/templates:go_default_library",
|
||||
|
|
@ -59,6 +60,7 @@ go_library(
|
|||
"//upup/pkg/fi/cloudup/gce:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/gcetasks:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/openstack:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/openstacktasks:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/vsphere:go_default_library",
|
||||
"//upup/pkg/fi/cloudup/vspheretasks:go_default_library",
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import (
|
|||
"k8s.io/kops/pkg/model/components"
|
||||
"k8s.io/kops/pkg/model/domodel"
|
||||
"k8s.io/kops/pkg/model/gcemodel"
|
||||
"k8s.io/kops/pkg/model/openstackmodel"
|
||||
"k8s.io/kops/pkg/model/vspheremodel"
|
||||
"k8s.io/kops/pkg/resources/digitalocean"
|
||||
"k8s.io/kops/pkg/templates"
|
||||
|
|
@ -57,6 +58,7 @@ import (
|
|||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/gcetasks"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/openstack"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/openstacktasks"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/vsphere"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/vspheretasks"
|
||||
|
|
@ -434,7 +436,15 @@ func (c *ApplyClusterCmd) Run() error {
|
|||
}
|
||||
|
||||
case kops.CloudProviderOpenstack:
|
||||
{
|
||||
osCloud := cloud.(openstack.OpenstackCloud)
|
||||
region = osCloud.Region()
|
||||
|
||||
l.AddTypes(map[string]interface{}{
|
||||
// Networking
|
||||
"network": &openstacktasks.Network{},
|
||||
})
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unknown CloudProvider %q", cluster.Spec.CloudProvider)
|
||||
}
|
||||
|
|
@ -551,6 +561,13 @@ func (c *ApplyClusterCmd) Run() error {
|
|||
// No special settings (yet!)
|
||||
|
||||
case kops.CloudProviderOpenstack:
|
||||
openstackModelContext := &openstackmodel.OpenstackModelContext{
|
||||
KopsModelContext: modelContext,
|
||||
}
|
||||
|
||||
l.Builders = append(l.Builders,
|
||||
&openstackmodel.NetworkModelBuilder{OpenstackModelContext: openstackModelContext, Lifecycle: &networkLifecycle},
|
||||
)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown cloudprovider %q", cluster.Spec.CloudProvider)
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ var writeBackoff = wait.Backoff{
|
|||
type OpenstackCloud interface {
|
||||
fi.Cloud
|
||||
|
||||
// Region returns the region which cloud will run on
|
||||
Region() string
|
||||
|
||||
// SetVolumeTags will set the tags for the Cinder volume
|
||||
SetVolumeTags(id string, tags map[string]string) error
|
||||
|
||||
|
|
@ -94,6 +97,7 @@ type openstackCloud struct {
|
|||
cinderClient *gophercloud.ServiceClient
|
||||
neutronClient *gophercloud.ServiceClient
|
||||
tags map[string]string
|
||||
region string
|
||||
}
|
||||
|
||||
var _ fi.Cloud = &openstackCloud{}
|
||||
|
|
@ -127,15 +131,21 @@ func NewOpenstackCloud(tags map[string]string) (OpenstackCloud, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("error building neutron client: %v", err)
|
||||
}
|
||||
region := endpointOpt.Region
|
||||
|
||||
c := &openstackCloud{
|
||||
cinderClient: cinderClient,
|
||||
neutronClient: neutronClient,
|
||||
tags: tags,
|
||||
region: region,
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *openstackCloud) Region() string {
|
||||
return c.region
|
||||
}
|
||||
|
||||
func (c *openstackCloud) ProviderID() kops.CloudProviderID {
|
||||
return kops.CloudProviderOpenstack
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue