|
|
@@ -1,5 +1,7 @@
|
|
|
package kubernetes
|
|
|
|
|
|
+import "github.com/porter-dev/porter/internal/models"
|
|
|
+
|
|
|
// KubeConfigCluster represents the cluster field in a kubeconfig
|
|
|
type KubeConfigCluster struct {
|
|
|
Cluster struct {
|
|
|
@@ -30,28 +32,15 @@ type KubeConfig struct {
|
|
|
Users []KubeConfigUser `yaml:"users"`
|
|
|
}
|
|
|
|
|
|
-// ClusterConfig represents the configuration for a single cluster-user pair. This gets
|
|
|
-// associated with a specific user, and is primarily used for simplicity.
|
|
|
-type ClusterConfig struct {
|
|
|
- // Name is the name of the cluster
|
|
|
- Name,
|
|
|
- // Server is the endpoint of the kube apiserver for a cluster
|
|
|
- Server,
|
|
|
- // Context is the name of the context
|
|
|
- Context,
|
|
|
- // User is the name of the user for a cluster
|
|
|
- User string
|
|
|
-}
|
|
|
-
|
|
|
-// ToClusterConfigs converts a KubeConfig to a set of ClusterConfigs by
|
|
|
+// ToClusterConfigs converts a KubeConfig to a set of ClusterConfigExternals by
|
|
|
// joining users and clusters on the context.
|
|
|
-func (k *KubeConfig) ToClusterConfigs() []*ClusterConfig {
|
|
|
- clusters := make([]*ClusterConfig, 0)
|
|
|
+func (k *KubeConfig) ToClusterConfigs() []*models.ClusterConfigExternal {
|
|
|
+ clusters := make([]*models.ClusterConfigExternal, 0)
|
|
|
|
|
|
// convert clusters, contexts, and users to maps for fast lookup
|
|
|
- clusterMap := k.CreateClusterMap()
|
|
|
- contextMap := k.CreateContextMap()
|
|
|
- userMap := k.CreateUserMap()
|
|
|
+ clusterMap := k.createClusterMap()
|
|
|
+ contextMap := k.createContextMap()
|
|
|
+ userMap := k.createUserMap()
|
|
|
|
|
|
// iterate through context maps and link to a user-cluster pair
|
|
|
for contextName, context := range contextMap {
|
|
|
@@ -61,7 +50,7 @@ func (k *KubeConfig) ToClusterConfigs() []*ClusterConfig {
|
|
|
cluster, clusterFound := clusterMap[clusterName]
|
|
|
|
|
|
if userFound && clusterFound {
|
|
|
- clusters = append(clusters, &ClusterConfig{
|
|
|
+ clusters = append(clusters, &models.ClusterConfigExternal{
|
|
|
Name: clusterName,
|
|
|
Server: cluster.Cluster.Server,
|
|
|
Context: contextName,
|
|
|
@@ -73,8 +62,8 @@ func (k *KubeConfig) ToClusterConfigs() []*ClusterConfig {
|
|
|
return clusters
|
|
|
}
|
|
|
|
|
|
-// CreateClusterMap creates a map from a cluster name to a KubeConfigCluster object
|
|
|
-func (k *KubeConfig) CreateClusterMap() map[string]KubeConfigCluster {
|
|
|
+// createClusterMap creates a map from a cluster name to a KubeConfigCluster object
|
|
|
+func (k *KubeConfig) createClusterMap() map[string]KubeConfigCluster {
|
|
|
clusterMap := make(map[string]KubeConfigCluster)
|
|
|
|
|
|
for _, cluster := range k.Clusters {
|
|
|
@@ -84,8 +73,8 @@ func (k *KubeConfig) CreateClusterMap() map[string]KubeConfigCluster {
|
|
|
return clusterMap
|
|
|
}
|
|
|
|
|
|
-// CreateContextMap creates a map from a context name to a KubeConfigContext object
|
|
|
-func (k *KubeConfig) CreateContextMap() map[string]KubeConfigContext {
|
|
|
+// createContextMap creates a map from a context name to a KubeConfigContext object
|
|
|
+func (k *KubeConfig) createContextMap() map[string]KubeConfigContext {
|
|
|
contextMap := make(map[string]KubeConfigContext)
|
|
|
|
|
|
for _, context := range k.Contexts {
|
|
|
@@ -95,8 +84,8 @@ func (k *KubeConfig) CreateContextMap() map[string]KubeConfigContext {
|
|
|
return contextMap
|
|
|
}
|
|
|
|
|
|
-// CreateUserMap creates a map from a user name to a KubeConfigUser object
|
|
|
-func (k *KubeConfig) CreateUserMap() map[string]KubeConfigUser {
|
|
|
+// createUserMap creates a map from a user name to a KubeConfigUser object
|
|
|
+func (k *KubeConfig) createUserMap() map[string]KubeConfigUser {
|
|
|
userMap := make(map[string]KubeConfigUser)
|
|
|
|
|
|
for _, user := range k.Users {
|