Subsume StatusStore into fi.Cloud

This commit is contained in:
John Gardiner Myers 2021-05-15 16:38:25 -07:00
parent af653a7842
commit dd605fdbc3
26 changed files with 137 additions and 177 deletions

View File

@ -132,7 +132,7 @@ func (c *MockGCECloud) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterSt
}
// GetApiIngressStatus implements GCECloud::GetApiIngressStatus
func (c *MockGCECloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func (c *MockGCECloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return nil, fmt.Errorf("MockGCECloud::GetApiIngressStatus not implemented")
}

View File

@ -243,8 +243,7 @@ func RunEditCluster(ctx context.Context, f *util.Factory, cmd *cobra.Command, ar
}
// Retrieve the current status of the cluster. This will eventually be part of the cluster object.
statusDiscovery := &commands.CloudDiscoveryStatusStore{}
status, err := statusDiscovery.FindClusterStatus(oldCluster)
status, err := cloud.FindClusterStatus(oldCluster)
if err != nil {
return err
}

View File

@ -27,8 +27,8 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kops/cmd/kops/util"
kopsapi "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/commands"
"k8s.io/kops/pkg/kubeconfig"
"k8s.io/kops/upup/pkg/fi/cloudup"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
)
@ -139,11 +139,15 @@ func RunExportKubecfg(ctx context.Context, f *util.Factory, out io.Writer, optio
return err
}
cloud, err := cloudup.BuildCloud(cluster)
if err != nil {
return err
}
conf, err := kubeconfig.BuildKubecfg(
cluster,
keyStore,
secretStore,
&commands.CloudDiscoveryStatusStore{},
cloud,
options.admin,
options.user,
options.internal,

View File

@ -27,8 +27,8 @@ import (
"k8s.io/klog/v2"
"k8s.io/kops/cmd/kops/util"
kopsapi "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/commands"
"k8s.io/kops/pkg/kopscodecs"
"k8s.io/kops/upup/pkg/fi/cloudup"
"k8s.io/kops/util/pkg/text"
"k8s.io/kops/util/pkg/vfs"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
@ -120,8 +120,11 @@ func RunReplace(ctx context.Context, f *util.Factory, cmd *cobra.Command, out io
case *kopsapi.Cluster:
{
// Retrieve the current status of the cluster. This will eventually be part of the cluster object.
statusDiscovery := &commands.CloudDiscoveryStatusStore{}
status, err := statusDiscovery.FindClusterStatus(v)
cloud, err := cloudup.BuildCloud(v)
if err != nil {
return err
}
status, err := cloud.FindClusterStatus(v)
if err != nil {
return err
}

View File

@ -32,7 +32,6 @@ import (
"k8s.io/klog/v2"
"k8s.io/kops/cmd/kops/util"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/commands"
"k8s.io/kops/pkg/kubeconfig"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup"
@ -318,7 +317,7 @@ func RunUpdateCluster(ctx context.Context, f *util.Factory, clusterName string,
cluster,
keyStore,
secretStore,
&commands.CloudDiscoveryStatusStore{},
cloud,
c.admin,
c.user,
c.internal,

View File

@ -16,14 +16,6 @@ limitations under the License.
package kops
// StatusStore abstracts the key status functions; and lets us introduce status gradually
type StatusStore interface {
// FindClusterStatus discovers the status of the cluster, by inspecting the cloud objects
FindClusterStatus(cluster *Cluster) (*ClusterStatus, error)
GetApiIngressStatus(cluster *Cluster) ([]ApiIngressStatus, error)
}
type ClusterStatus struct {
// EtcdClusters stores the status for each cluster
EtcdClusters []EtcdClusterStatus `json:"etcdClusters,omitempty"`
@ -44,17 +36,3 @@ type EtcdMemberStatus struct {
// volumeId is the id of the cloud volume (e.g. the AWS volume id)
VolumeId string `json:"volumeId,omitempty"`
}
// ApiIngressStatus represents the status of an ingress point:
// traffic intended for the service should be sent to an ingress point.
type ApiIngressStatus struct {
// IP is set for load-balancer ingress points that are IP based
// (typically GCE or OpenStack load-balancers)
// +optional
IP string `json:"ip,omitempty" protobuf:"bytes,1,opt,name=ip"`
// Hostname is set for load-balancer ingress points that are DNS based
// (typically AWS load-balancers)
// +optional
Hostname string `json:"hostname,omitempty" protobuf:"bytes,2,opt,name=hostname"`
}

View File

@ -91,7 +91,7 @@ func validateEtcdClusterUpdate(fp *field.Path, obj kops.EtcdClusterSpec, status
fp := fp.Child("etcdMembers").Key(k)
if oldMember, ok := oldMembers[k]; ok {
allErrs = append(allErrs, validateEtcdMemberUpdate(fp, newMember, etcdClusterStatus, oldMember)...)
allErrs = append(allErrs, validateEtcdMemberUpdate(fp, newMember, oldMember)...)
}
}
}
@ -99,7 +99,7 @@ func validateEtcdClusterUpdate(fp *field.Path, obj kops.EtcdClusterSpec, status
return allErrs
}
func validateEtcdMemberUpdate(fp *field.Path, obj kops.EtcdMemberSpec, status *kops.EtcdClusterStatus, old kops.EtcdMemberSpec) field.ErrorList {
func validateEtcdMemberUpdate(fp *field.Path, obj kops.EtcdMemberSpec, old kops.EtcdMemberSpec) field.ErrorList {
allErrs := field.ErrorList{}
if obj.Name != old.Name {

View File

@ -183,22 +183,6 @@ func (in *AmazonVPCNetworkingSpec) DeepCopy() *AmazonVPCNetworkingSpec {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ApiIngressStatus) DeepCopyInto(out *ApiIngressStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApiIngressStatus.
func (in *ApiIngressStatus) DeepCopy() *ApiIngressStatus {
if in == nil {
return nil
}
out := new(ApiIngressStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Assets) DeepCopyInto(out *Assets) {
*out = *in

View File

@ -7,7 +7,6 @@ go_library(
"helpers_readwrite.go",
"set_cluster.go",
"set_instancegroups.go",
"status_discovery.go",
"version.go",
],
importpath = "k8s.io/kops/pkg/commands",

View File

@ -52,8 +52,7 @@ func UpdateCluster(ctx context.Context, clientset simple.Clientset, cluster *kop
}
// Retrieve the current status of the cluster. This will eventually be part of the cluster object.
statusDiscovery := &CloudDiscoveryStatusStore{}
status, err := statusDiscovery.FindClusterStatus(cluster)
status, err := cloud.FindClusterStatus(cluster)
if err != nil {
return err
}

View File

@ -1,48 +0,0 @@
/*
Copyright 2017 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 commands
import (
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi/cloudup"
)
// CloudDiscoveryStatusStore implements status.Store by inspecting cloud objects.
// Likely temporary until we validate our status usage
type CloudDiscoveryStatusStore struct {
}
var _ kops.StatusStore = &CloudDiscoveryStatusStore{}
func (s *CloudDiscoveryStatusStore) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
cloud, err := cloudup.BuildCloud(cluster)
if err != nil {
return nil, err
}
return cloud.GetApiIngressStatus(cluster)
}
// FindClusterStatus discovers the status of the cluster, by inspecting the cloud objects
func (s *CloudDiscoveryStatusStore) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error) {
cloud, err := cloudup.BuildCloud(cluster)
if err != nil {
return nil, err
}
return cloud.FindClusterStatus(cluster)
}

View File

@ -28,11 +28,14 @@ go_test(
srcs = ["create_kubecfg_test.go"],
embed = [":go_default_library"],
deps = [
"//dnsprovider/pkg/dnsprovider:go_default_library",
"//pkg/apis/kops:go_default_library",
"//pkg/cloudinstances:go_default_library",
"//pkg/pki:go_default_library",
"//pkg/testutils:go_default_library",
"//upup/pkg/fi:go_default_library",
"//util/pkg/vfs:go_default_library",
"//vendor/github.com/google/go-cmp/cmp:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
],
)

View File

@ -34,7 +34,7 @@ import (
const DefaultKubecfgAdminLifetime = 18 * time.Hour
func BuildKubecfg(cluster *kops.Cluster, keyStore fi.Keystore, secretStore fi.SecretStore, status kops.StatusStore, admin time.Duration, configUser string, internal bool, kopsStateStore string, useKopsAuthenticationPlugin bool) (*KubeconfigBuilder, error) {
func BuildKubecfg(cluster *kops.Cluster, keyStore fi.Keystore, secretStore fi.SecretStore, cloud fi.Cloud, admin time.Duration, configUser string, internal bool, kopsStateStore string, useKopsAuthenticationPlugin bool) (*KubeconfigBuilder, error) {
clusterName := cluster.ObjectMeta.Name
var master string
@ -71,7 +71,7 @@ func BuildKubecfg(cluster *kops.Cluster, keyStore fi.Keystore, secretStore fi.Se
}
if useELBName {
ingresses, err := status.GetApiIngressStatus(cluster)
ingresses, err := cloud.GetApiIngressStatus(cluster)
if err != nil {
return nil, fmt.Errorf("error getting ingress status: %v", err)
}

View File

@ -21,6 +21,9 @@ import (
"testing"
"time"
v1 "k8s.io/api/core/v1"
"k8s.io/kops/dnsprovider/pkg/dnsprovider"
"k8s.io/kops/pkg/cloudinstances"
"k8s.io/kops/pkg/testutils"
"github.com/google/go-cmp/cmp"
@ -34,19 +37,52 @@ const certData = "-----BEGIN CERTIFICATE-----\nMIIC2DCCAcCgAwIBAgIRALJXAkVj964tq
const privatekeyData = "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA4JwpEprZ5n8RIEt6jT2lAh+UDgRgx/4px21gjgywQivYHVxH\nAZexVb/E9pBa9Q2G9B1Q7TCO7YsUVRQy4JMDZVt+McFnWVwexnqBYFNcVjkEmDgA\ngvCYGE0P9d/RwRL4KuLHo+u6fv7P0jXMN+CpOxyLhYZZNa0ZOZDHsSiJSQSj9WGF\nGHrbCf0KVDpKieR1uBqHrRO+mLR5zkX2L58m74kjK4dsBhmjeq/7OAoTmiG2QgJ/\nP2IjyhiA2mRqY+hl55lwEUV/0yHYEkJC8LdGkwwZz2eF77aSPGmi/A2CSKgMwDTx\n9m+P7jcpWreYw6NG9BueGoDIve/tgFKwvVFF6QIDAQABAoIBAA0ktjaTfyrAxsTI\nBezb7Zr5NBW55dvuII299cd6MJo+rI/TRYhvUv48kY8IFXp/hyUjzgeDLunxmIf9\n/Zgsoic9Ol44/g45mMduhcGYPzAAeCdcJ5OB9rR9VfDCXyjYLlN8H8iU0734tTqM\n0V13tQ9zdSqkGPZOIcq/kR/pylbOZaQMe97BTlsAnOMSMKDgnftY4122Lq3GYy+t\nvpr+bKVaQZwvkLoSU3rECCaKaghgwCyX7jft9aEkhdJv+KlwbsGY6WErvxOaLWHd\ncuMQjGapY1Fa/4UD00mvrA260NyKfzrp6+P46RrVMwEYRJMIQ8YBAk6N6Hh7dc0G\n8Z6i1m0CgYEA9HeCJR0TSwbIQ1bDXUrzpftHuidG5BnSBtax/ND9qIPhR/FBW5nj\n22nwLc48KkyirlfIULd0ae4qVXJn7wfYcuX/cJMLDmSVtlM5Dzmi/91xRiFgIzx1\nAsbBzaFjISP2HpSgL+e9FtSXaaqeZVrflitVhYKUpI/AKV31qGHf04sCgYEA6zTV\n99Sb49Wdlns5IgsfnXl6ToRttB18lfEKcVfjAM4frnkk06JpFAZeR+9GGKUXZHqs\nz2qcplw4d/moCC6p3rYPBMLXsrGNEUFZqBlgz72QA6BBq3X0Cg1Bc2ZbK5VIzwkg\nST2SSux6ccROfgULmN5ZiLOtdUKNEZpFF3i3qtsCgYADT/s7dYFlatobz3kmMnXK\nsfTu2MllHdRys0YGHu7Q8biDuQkhrJwhxPW0KS83g4JQym+0aEfzh36bWcl+u6R7\nKhKj+9oSf9pndgk345gJz35RbPJYh+EuAHNvzdgCAvK6x1jETWeKf6btj5pF1U1i\nQ4QNIw/QiwIXjWZeubTGsQKBgQCbduLu2rLnlyyAaJZM8DlHZyH2gAXbBZpxqU8T\nt9mtkJDUS/KRiEoYGFV9CqS0aXrayVMsDfXY6B/S/UuZjO5u7LtklDzqOf1aKG3Q\ndGXPKibknqqJYH+bnUNjuYYNerETV57lijMGHuSYCf8vwLn3oxBfERRX61M/DU8Z\nworz/QKBgQDCTJI2+jdXg26XuYUmM4XXfnocfzAXhXBULt1nENcogNf1fcptAVtu\nBAiz4/HipQKqoWVUYmxfgbbLRKKLK0s0lOWKbYdVjhEm/m2ZU8wtXTagNwkIGoyq\nY/C1Lox4f1ROJnCjc/hfcOjcxX5M8A8peecHWlVtUPKTJgxQ7oMKcw==\n-----END RSA PRIVATE KEY-----\n"
// mock a fake status store.
type fakeStatusStore struct {
FindClusterStatusFn func(cluster *kops.Cluster) (*kops.ClusterStatus, error)
GetApiIngressStatusFn func(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error)
type fakeStatusCloud struct {
GetApiIngressStatusFn func(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error)
}
func (f fakeStatusStore) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error) {
return f.FindClusterStatusFn(cluster)
}
var _ fi.Cloud = &fakeStatusCloud{}
func (f fakeStatusStore) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func (f fakeStatusCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return f.GetApiIngressStatusFn(cluster)
}
func (f fakeStatusCloud) ProviderID() kops.CloudProviderID {
panic("not implemented")
}
func (f fakeStatusCloud) DNS() (dnsprovider.Interface, error) {
panic("not implemented")
}
func (f fakeStatusCloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {
panic("not implemented")
}
func (f fakeStatusCloud) DeleteInstance(instance *cloudinstances.CloudInstance) error {
panic("not implemented")
}
func (f fakeStatusCloud) DeleteGroup(group *cloudinstances.CloudInstanceGroup) error {
panic("not implemented")
}
func (f fakeStatusCloud) DetachInstance(instance *cloudinstances.CloudInstance) error {
panic("not implemented")
}
func (f fakeStatusCloud) GetCloudGroups(cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) {
panic("not implemented")
}
func (f fakeStatusCloud) Region() string {
panic("not implemented")
}
func (f fakeStatusCloud) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error) {
panic("not implemented")
}
// mock a fake key store
type fakeKeyStore struct {
FindKeypairFn func(name string) (*pki.Certificate, *pki.PrivateKey, bool, error)
@ -110,7 +146,7 @@ func TestBuildKubecfg(t *testing.T) {
type args struct {
cluster *kops.Cluster
secretStore fi.SecretStore
status fakeStatusStore
status fakeStatusCloud
admin time.Duration
user string
internal bool
@ -135,7 +171,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Public DNS with admin",
args: args{
cluster: publicCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: DefaultKubecfgAdminLifetime,
user: "",
},
@ -151,7 +187,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Public DNS with admin and secondary NLB port",
args: args{
cluster: certNLBCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: DefaultKubecfgAdminLifetime,
},
want: &KubeconfigBuilder{
@ -166,7 +202,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Public DNS with admin and CLB ACM Certificate",
args: args{
cluster: certCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: DefaultKubecfgAdminLifetime,
},
want: &KubeconfigBuilder{
@ -181,7 +217,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Public DNS without admin and with ACM certificate",
args: args{
cluster: certNLBCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: 0,
},
want: &KubeconfigBuilder{
@ -196,7 +232,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Public DNS without admin",
args: args{
cluster: publicCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: 0,
user: "myuser",
},
@ -212,7 +248,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Public DNS with Empty Master Name",
args: args{
cluster: emptyMasterPublicNameCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: 0,
user: "",
},
@ -228,9 +264,9 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Gossip cluster",
args: args{
cluster: gossipCluster,
status: fakeStatusStore{
GetApiIngressStatusFn: func(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
return []kops.ApiIngressStatus{
status: fakeStatusCloud{
GetApiIngressStatusFn: func(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return []fi.ApiIngressStatus{
{
Hostname: "elbHostName",
},
@ -250,7 +286,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Public DNS with kops auth plugin",
args: args{
cluster: publicCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: 0,
useKopsAuthenticationPlugin: true,
},
@ -273,7 +309,7 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For internal DNS name with admin",
args: args{
cluster: publicCluster,
status: fakeStatusStore{},
status: fakeStatusCloud{},
admin: DefaultKubecfgAdminLifetime,
internal: true,
},
@ -289,9 +325,9 @@ func TestBuildKubecfg(t *testing.T) {
name: "Test Kube Config Data For Gossip cluster with admin and secondary NLB port",
args: args{
cluster: certGossipNLBCluster,
status: fakeStatusStore{
GetApiIngressStatusFn: func(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
return []kops.ApiIngressStatus{
status: fakeStatusCloud{
GetApiIngressStatusFn: func(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return []fi.ApiIngressStatus{
{
Hostname: "nlbHostName",
},

View File

@ -199,8 +199,8 @@ func (c *Cloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {
return nil, errors.New("not implemented")
}
func (c *Cloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
var ingresses []kops.ApiIngressStatus
func (c *Cloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
var ingresses []fi.ApiIngressStatus
if cluster.Spec.MasterPublicName != "" {
// Note that this must match Digital Ocean's lb name
klog.V(2).Infof("Querying DO to find Loadbalancers for API (%q)", cluster.Name)
@ -221,7 +221,7 @@ func (c *Cloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressSta
}
address := lb.IP
ingresses = append(ingresses, kops.ApiIngressStatus{IP: address})
ingresses = append(ingresses, fi.ApiIngressStatus{IP: address})
return ingresses, nil
}

View File

@ -24,8 +24,6 @@ import (
)
type Cloud interface {
kops.StatusStore
ProviderID() kops.CloudProviderID
DNS() (dnsprovider.Interface, error)
@ -49,6 +47,11 @@ type Cloud interface {
// Region returns the cloud region bound to the cloud instance.
// If the region concept does not apply, returns "".
Region() string
// FindClusterStatus discovers the status of the cluster, by inspecting the cloud objects
FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error)
GetApiIngressStatus(cluster *kops.Cluster) ([]ApiIngressStatus, error)
}
type VPCInfo struct {
@ -65,6 +68,20 @@ type SubnetInfo struct {
CIDR string
}
// ApiIngressStatus represents the status of an ingress point:
// traffic intended for the service should be sent to an ingress point.
type ApiIngressStatus struct {
// IP is set for load-balancer ingress points that are IP based
// (typically GCE or OpenStack load-balancers)
// +optional
IP string `json:"ip,omitempty" protobuf:"bytes,1,opt,name=ip"`
// Hostname is set for load-balancer ingress points that are DNS based
// (typically AWS load-balancers)
// +optional
Hostname string `json:"hostname,omitempty" protobuf:"bytes,2,opt,name=hostname"`
}
// zonesToCloud allows us to infer from certain well-known zones to a cloud
// Note it is safe to "overmap" zones that don't exist: we'll check later if the zones actually exist
var zonesToCloud = map[string]kops.CloudProviderID{

View File

@ -70,8 +70,6 @@ type ALICloud interface {
CreateTags(resourceId string, resourceType string, tags map[string]string) error
RemoveTags(resourceId string, resourceType string, tags map[string]string) error
GetClusterTags() map[string]string
FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error)
GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error)
}
type aliCloudImplementation struct {
@ -342,8 +340,8 @@ func (c *aliCloudImplementation) GetClusterTags() map[string]string {
return c.tags
}
func (c *aliCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
var ingresses []kops.ApiIngressStatus
func (c *aliCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
var ingresses []fi.ApiIngressStatus
name := "api." + cluster.Name
describeLoadBalancersArgs := &slb.DescribeLoadBalancersArgs{
@ -364,7 +362,7 @@ func (c *aliCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]k
}
address := responseLoadBalancers[0].Address
ingresses = append(ingresses, kops.ApiIngressStatus{IP: address})
ingresses = append(ingresses, fi.ApiIngressStatus{IP: address})
return ingresses, nil
}

View File

@ -177,9 +177,6 @@ type AWSCloud interface {
// DescribeInstanceType calls ec2.DescribeInstanceType to get information for a particular instance type
DescribeInstanceType(instanceType string) (*ec2.InstanceTypeInfo, error)
// FindClusterStatus gets the status of the cluster as it exists in AWS, inferred from volumes
FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error)
// AccountInfo returns the AWS account ID and AWS partition that we are deploying into
AccountInfo() (string, string, error)
}
@ -1868,16 +1865,16 @@ func findVPCInfo(c AWSCloud, vpcID string) (*fi.VPCInfo, error) {
return vpcInfo, nil
}
func (c *awsCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func (c *awsCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return getApiIngressStatus(c, cluster)
}
func getApiIngressStatus(c AWSCloud, cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
var ingresses []kops.ApiIngressStatus
func getApiIngressStatus(c AWSCloud, cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
var ingresses []fi.ApiIngressStatus
if lbDnsName, err := findDNSName(c, cluster); err != nil {
return nil, fmt.Errorf("error finding aws DNSName: %v", err)
} else if lbDnsName != "" {
ingresses = append(ingresses, kops.ApiIngressStatus{Hostname: lbDnsName})
ingresses = append(ingresses, fi.ApiIngressStatus{Hostname: lbDnsName})
}
return ingresses, nil

View File

@ -301,7 +301,7 @@ func (c *MockAWSCloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {
return findVPCInfo(c, id)
}
func (c *MockAWSCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func (c *MockAWSCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return getApiIngressStatus(c, cluster)
}

View File

@ -42,8 +42,6 @@ type AzureCloud interface {
fi.Cloud
AddClusterTags(tags map[string]*string)
FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error)
GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error)
SubscriptionID() string
ResourceGroup() ResourceGroupsClient
@ -138,8 +136,8 @@ func (c *azureCloudImplementation) AddClusterTags(tags map[string]*string) {
}
}
func (c *azureCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
var ingresses []kops.ApiIngressStatus
func (c *azureCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
var ingresses []fi.ApiIngressStatus
var rg string = cluster.AzureResourceGroupName()
lbSpec := cluster.Spec.API.LoadBalancer
@ -167,7 +165,7 @@ func (c *azureCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([
if i.FrontendIPConfigurationPropertiesFormat.PrivateIPAddress == nil {
continue
}
ingresses = append(ingresses, kops.ApiIngressStatus{
ingresses = append(ingresses, fi.ApiIngressStatus{
IP: *i.FrontendIPConfigurationPropertiesFormat.PrivateIPAddress,
})
case kops.LoadBalancerTypePublic:
@ -176,7 +174,7 @@ func (c *azureCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([
i.FrontendIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPAddress == nil {
continue
}
ingresses = append(ingresses, kops.ApiIngressStatus{
ingresses = append(ingresses, fi.ApiIngressStatus{
IP: *i.FrontendIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPAddress,
})
default:
@ -213,7 +211,7 @@ func (c *azureCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([
continue
}
for _, i := range *ni.IPConfigurations {
ingresses = append(ingresses, kops.ApiIngressStatus{
ingresses = append(ingresses, fi.ApiIngressStatus{
IP: *i.PrivateIPAddress,
})
}

View File

@ -158,7 +158,7 @@ func (c *MockAzureCloud) FindClusterStatus(cluster *kops.Cluster) (*kops.Cluster
}
// GetApiIngressStatus returns the status of API ingress.
func (c *MockAzureCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func (c *MockAzureCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return nil, nil
}

View File

@ -45,12 +45,8 @@ type GCECloud interface {
Project() string
WaitForOp(op *compute.Operation) error
GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error)
Labels() map[string]string
// FindClusterStatus gets the status of the cluster as it exists in GCE, inferred from volumes
FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error)
Zones() ([]string, error)
// ServiceAccount returns the email for the service account that the instances will run under
@ -288,8 +284,8 @@ func (c *gceCloudImplementation) WaitForOp(op *compute.Operation) error {
return WaitForOp(c.compute.srv, op)
}
func (c *gceCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
var ingresses []kops.ApiIngressStatus
func (c *gceCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
var ingresses []fi.ApiIngressStatus
// Note that this must match GCEModelContext::NameForForwardingRule
name := SafeObjectName("api", cluster.ObjectMeta.Name)
@ -309,7 +305,7 @@ func (c *gceCloudImplementation) GetApiIngressStatus(cluster *kops.Cluster) ([]k
return nil, fmt.Errorf("found forward rule %q, but it did not have an IPAddress", name)
}
ingresses = append(ingresses, kops.ApiIngressStatus{
ingresses = append(ingresses, fi.ApiIngressStatus{
IP: forwardingRule.IPAddress,
})
}

View File

@ -79,6 +79,7 @@ go_test(
embed = [":go_default_library"],
deps = [
"//pkg/apis/kops:go_default_library",
"//upup/pkg/fi:go_default_library",
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers:go_default_library",

View File

@ -264,10 +264,6 @@ type OpenstackCloud interface {
// DeleteLB will delete loadbalancer
DeleteLB(lbID string, opt loadbalancers.DeleteOpts) error
GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error)
FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error)
// DefaultInstanceType determines a suitable instance type for the specified instance group
DefaultInstanceType(cluster *kops.Cluster, ig *kops.InstanceGroup) (string, error)
@ -664,11 +660,11 @@ type Address struct {
Addr string
}
func (c *openstackCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func (c *openstackCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return getApiIngressStatus(c, cluster)
}
func getApiIngressStatus(c OpenstackCloud, cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func getApiIngressStatus(c OpenstackCloud, cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
if cluster.Spec.CloudConfig.Openstack.Loadbalancer != nil {
return getLoadBalancerIngressStatus(c, cluster)
} else {
@ -676,8 +672,8 @@ func getApiIngressStatus(c OpenstackCloud, cluster *kops.Cluster) ([]kops.ApiIng
}
}
func getLoadBalancerIngressStatus(c OpenstackCloud, cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
var ingresses []kops.ApiIngressStatus
func getLoadBalancerIngressStatus(c OpenstackCloud, cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
var ingresses []fi.ApiIngressStatus
if cluster.Spec.MasterPublicName != "" {
// Note that this must match OpenstackModel lb name
klog.V(2).Infof("Querying Openstack to find Loadbalancers for API (%q)", cluster.Name)
@ -697,7 +693,7 @@ func getLoadBalancerIngressStatus(c OpenstackCloud, cluster *kops.Cluster) ([]ko
}
for _, fip := range fips {
if fip.PortID == lb.VipPortID {
ingresses = append(ingresses, kops.ApiIngressStatus{
ingresses = append(ingresses, fi.ApiIngressStatus{
IP: fip.FloatingIP,
})
}
@ -707,7 +703,7 @@ func getLoadBalancerIngressStatus(c OpenstackCloud, cluster *kops.Cluster) ([]ko
return ingresses, nil
}
func getIPIngressStatus(c OpenstackCloud, cluster *kops.Cluster) (ingresses []kops.ApiIngressStatus, err error) {
func getIPIngressStatus(c OpenstackCloud, cluster *kops.Cluster) (ingresses []fi.ApiIngressStatus, err error) {
done, err := vfs.RetryWithBackoff(readBackoff, func() (bool, error) {
instances, err := c.ListInstances(servers.ListOpts{})
if err != nil {
@ -725,7 +721,7 @@ func getIPIngressStatus(c OpenstackCloud, cluster *kops.Cluster) (ingresses []ko
if err != nil {
return false, fmt.Errorf("failed to get interface address: %v", err)
}
ingresses = append(ingresses, kops.ApiIngressStatus{
ingresses = append(ingresses, fi.ApiIngressStatus{
IP: address,
})
} else {
@ -734,7 +730,7 @@ func getIPIngressStatus(c OpenstackCloud, cluster *kops.Cluster) (ingresses []ko
return false, err
}
for _, ip := range ips {
ingresses = append(ingresses, kops.ApiIngressStatus{
ingresses = append(ingresses, fi.ApiIngressStatus{
IP: fi.StringValue(ip),
})
}

View File

@ -31,6 +31,7 @@ import (
l3floatingips "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
)
func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
@ -41,7 +42,7 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
l3FloatingIPs []l3floatingips.FloatingIP
instances serverList
cloudFloatingEnabled bool
expectedAPIIngress []kops.ApiIngressStatus
expectedAPIIngress []fi.ApiIngressStatus
expectedError error
}{
{
@ -74,7 +75,7 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
FloatingIP: "8.8.8.8",
},
},
expectedAPIIngress: []kops.ApiIngressStatus{
expectedAPIIngress: []fi.ApiIngressStatus{
{
IP: "8.8.8.8",
},
@ -122,7 +123,7 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
FloatingIP: "9.9.9.9",
},
},
expectedAPIIngress: []kops.ApiIngressStatus{
expectedAPIIngress: []fi.ApiIngressStatus{
{IP: "8.8.8.8"},
},
},
@ -200,7 +201,7 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
},
},
},
expectedAPIIngress: []kops.ApiIngressStatus{
expectedAPIIngress: []fi.ApiIngressStatus{
{IP: "1.2.3.4"},
{IP: "2.3.4.5"},
{IP: "3.4.5.6"},
@ -273,7 +274,7 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
},
},
cloudFloatingEnabled: true,
expectedAPIIngress: []kops.ApiIngressStatus{
expectedAPIIngress: []fi.ApiIngressStatus{
{IP: "1.2.3.4"},
{IP: "4.5.6.7"},
{IP: "40.50.60.70"},
@ -390,7 +391,7 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
}
}
type sortByIP []kops.ApiIngressStatus
type sortByIP []fi.ApiIngressStatus
// Len is the number of elements in the collection.
func (s sortByIP) Len() int {

View File

@ -303,7 +303,7 @@ func (c *MockCloud) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatu
func (c *MockCloud) FindNetworkBySubnetID(subnetID string) (*networks.Network, error) {
return findNetworkBySubnetID(c, subnetID)
}
func (c *MockCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiIngressStatus, error) {
func (c *MockCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return getApiIngressStatus(c, cluster)
}
func (c *MockCloud) GetCloudTags() map[string]string {