Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KubedirectorCluster Connections #283

Merged
merged 82 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
55c3c1f
attachments first push
kmathur2 Dec 5, 2019
d899a9c
add function comments
kmathur2 Dec 5, 2019
fd050cd
model as a config map
kmathur2 Jan 16, 2020
4274f9c
remove model object
kmathur2 Jan 16, 2020
479a5c2
attachment should have model which is a map of map name and value as …
kmathur2 Jan 16, 2020
2c62a0d
testing app changes
kmathur2 Jan 21, 2020
d1ce820
Merge branch 'master' of https://github.com/bluek8s/kubedirector into…
kmathur2 Jan 21, 2020
2ce8d19
add watcher and stuff
kmathur2 Jan 22, 2020
ab008d1
generate configmeta and push inside pods
kmathur2 Jan 23, 2020
247cc2f
some refactoring
kmathur2 Jan 24, 2020
241d92c
some more cleanup
kmathur2 Jan 24, 2020
35f69ed
fix domain base
kmathur2 Feb 4, 2020
51c561c
fix merge conflicts
kmathur2 Feb 4, 2020
f9c18e8
fix examples
kmathur2 Feb 4, 2020
8e1a4b4
fix merge conflicts
kmathur2 Feb 26, 2020
0b32e00
Merge branch 'master' of https://github.com/bluek8s/kubedirector into…
kmathur2 Feb 26, 2020
3004567
resolve more conflicts
kmathur2 Feb 26, 2020
9fed699
push first cut basic
kmathur2 Mar 3, 2020
a442dd0
Merge branch 'master' of https://github.com/bluek8s/kubedirector into…
kmathur2 Mar 3, 2020
bb84c5f
add stuff
kmathur2 Mar 3, 2020
370d66c
wip for connections
kmathur2 Mar 4, 2020
0e5ac56
more configmeta generator changes
kmathur2 Mar 9, 2020
1ab32cb
remove unrequired code
kmathur2 Mar 9, 2020
1b823b8
config map could be really generic
kmathur2 Mar 10, 2020
c500f5b
lets call it connections instead of attachments
kmathur2 Mar 10, 2020
77659a9
fix more attachment to connection renaming
kmathur2 Mar 10, 2020
acb59b1
don't need to expose initRole now
kmathur2 Mar 10, 2020
33e0e60
remove lock
kmathur2 Mar 11, 2020
3d563d9
all renaming attach->connect
kmathur2 Mar 11, 2020
fb6373e
minor fixes
kmathur2 Mar 11, 2020
c72eb9d
add accidental deletion of Gopkg.lock and Gopkg.toml
kmathur2 Mar 11, 2020
8c02619
fix golint
kmathur2 Mar 11, 2020
e3bed9f
minor tweaks continue
kmathur2 Mar 11, 2020
de30e6c
and more cleansing
kmathur2 Mar 11, 2020
8ee67ee
first cut working with connections
kmathur2 Mar 17, 2020
90e0972
add patch in validator
kmathur2 Mar 18, 2020
b37d58b
if a connected cluster's configmeta changes then notify the connectee
kmathur2 Mar 18, 2020
5269bc4
cleanup begins
kmathur2 Mar 20, 2020
705e816
more cleanup
kmathur2 Mar 20, 2020
6e86fee
fix comments
kmathur2 Mar 20, 2020
c7afc5c
configmap reconciler changes
kmathur2 Mar 25, 2020
acb8b26
set cluster status to nil from configmap reconciller
kmathur2 Mar 25, 2020
b67b112
set cluster status to nil from configmap reconciller
kmathur2 Mar 25, 2020
d5fab4e
clean up reconciler
kmathur2 Mar 25, 2020
bbdfc76
set status to nil
kmathur2 Mar 26, 2020
9950da1
ignore UID checks if configmetaGen has changed
kmathur2 Mar 26, 2020
703de4f
add logging
kmathur2 Mar 26, 2020
618ae3a
refactoring continues
kmathur2 Mar 26, 2020
1a9838e
fix merge conflicts
kmathur2 Mar 27, 2020
887cd08
cluster reconciler fixes
kmathur2 Mar 28, 2020
83bb2cc
Merge branch 'master' of https://github.com/bluek8s/kubedirector into…
kmathur2 Mar 28, 2020
1ba0328
refactoring continues
kmathur2 Mar 28, 2020
d0a9a36
review feedback v1
kmathur2 Apr 1, 2020
a730f05
overwrite LastSetupGeneration when there is no notfication and other…
kmathur2 Apr 3, 2020
f1b4972
remove commented
kmathur2 Apr 3, 2020
7296ca2
remove validator
kmathur2 Apr 3, 2020
5693cf3
back to old code
kmathur2 Apr 3, 2020
674ddca
remove validator
kmathur2 Apr 3, 2020
b1252e6
removed lock
kmathur2 Apr 3, 2020
c2a6a11
cleanup continues
kmathur2 Apr 3, 2020
b45033c
minor optimization
kmathur2 Apr 3, 2020
8bf3efd
configMetaGenerator and lastConfigMetaGenerator should be int64
kmathur2 Apr 3, 2020
20b63f3
remove redundant code
kmathur2 Apr 7, 2020
f2de3e3
remove unwanted code
kmathur2 Apr 7, 2020
cfa7a07
more review feedback addressed
kmathur2 Apr 14, 2020
5fab4b5
Merge branch 'master' of https://github.com/bluek8s/kubedirector into…
kmathur2 Apr 14, 2020
e0f2a9a
fixes around invalid incoming UID
kmathur2 Apr 15, 2020
19ac0f5
update log message
kmathur2 Apr 15, 2020
3d3f5c0
fix log message
kmathur2 Apr 15, 2020
c39ad15
fix log messages
kmathur2 Apr 15, 2020
b6a1541
remove empty lines
kmathur2 Apr 15, 2020
a086fae
remove empty lines
kmathur2 Apr 15, 2020
7b4c729
remove example files
kmathur2 Apr 15, 2020
325ae8e
add log message in cluster when connection changes
kmathur2 Apr 15, 2020
b6ce938
add accidentail removal of omitempty
kmathur2 Apr 15, 2020
8506f69
incorrect comment
kmathur2 Apr 15, 2020
1529b8c
log msg fixes and crd update
kmathur2 Apr 17, 2020
a73caff
minor optimization
kmathur2 Apr 17, 2020
53b078d
if get fails keep trying
kmathur2 Apr 17, 2020
86ece72
logging changes continues...
kmathur2 Apr 17, 2020
438490c
loggggg
kmathur2 Apr 17, 2020
f6316ac
change log obj
kmathur2 Apr 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ spec:
appCatalog:
type: string
pattern: '^local$|^system$'
connections:
type: object
properties:
clusters:
type: array
items:
type: string
configmaps:
type: array
items:
type: string
serviceType:
type: string
pattern: '^ClusterIP$|^NodePort$|^LoadBalancer$'
Expand All @@ -56,6 +67,8 @@ spec:
maximum: 511
readOnly:
type: boolean
connectionsGenerationToProcess:
type: integer
roles:
type: array
items:
Expand Down Expand Up @@ -197,6 +210,8 @@ spec:
type: boolean
generationUID:
type: string
lastConnectionsGeneration:
type: integer
specGenerationToProcess:
type: integer
clusterService:
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/kubedirector/v1beta1/kubedirectorapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ type KubeDirectorAppSpec struct {
type KubeDirectorApp struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KubeDirectorAppSpec `json:"spec,omitempty"`
Spec KubeDirectorAppSpec `json:"spec,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -82,9 +81,10 @@ type SetupPackageURL struct {
// access, and/or identified for other use by API clients or consumers
// internal to the virtual cluster (e.g. app setup packages).
type Service struct {
ID string `json:"id"`
Label Label `json:"label,omitempty"`
Endpoint ServiceEndpoint `json:"endpoint,omitempty"`
ID string `json:"id"`
Label Label `json:"label,omitempty"`
Endpoint ServiceEndpoint `json:"endpoint,omitempty"`
ExportedService string `json:"exported_service,omitempty"`
}

// ServiceEndpoint describes the service network address and protocol, and
Expand Down
27 changes: 18 additions & 9 deletions pkg/apis/kubedirector/v1beta1/kubedirectorcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ import (
// requested cluster roles, each of which will be implemented (by KubeDirector)
// using a StatefulSet.
type KubeDirectorClusterSpec struct {
AppID string `json:"app"`
AppCatalog *string `json:"appCatalog,omitempty"`
ServiceType *string `json:"serviceType,omitempty"`
Roles []Role `json:"roles"`
DefaultSecret *KDSecret `json:"defaultSecret,omitempty"`
AppID string `json:"app"`
AppCatalog *string `json:"appCatalog,omitempty"`
ServiceType *string `json:"serviceType,omitempty"`
Roles []Role `json:"roles"`
DefaultSecret *KDSecret `json:"defaultSecret,omitempty"`
ConnectionsGenToProcess int64 `json:"connectionsGenerationToProcess"`
Connections Connections `json:"connections"`
}

// Connections specifies list of cluster objects and configmaps objects that has
// be connected to the cluster.
type Connections struct {
Clusters []string `json:"clusters,omitempty"`
ConfigMaps []string `json:"configmaps,omitempty"`
}

// KubeDirectorClusterStatus defines the observed state of KubeDirectorCluster.
Expand All @@ -43,6 +52,7 @@ type KubeDirectorClusterStatus struct {
ClusterService string `json:"clusterService"`
LastNodeID int64 `json:"lastNodeID"`
Roles []RoleStatus `json:"roles"`
LastConnectionGen int64 `json:"lastConnectionsGeneration"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -57,10 +67,9 @@ type KubeDirectorClusterStatus struct {
type KubeDirectorCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KubeDirectorClusterSpec `json:"spec,omitempty"`
Status *KubeDirectorClusterStatus `json:"status,omitempty"`
AppSpec *KubeDirectorApp `json:"-"`
Spec KubeDirectorClusterSpec `json:"spec,omitempty"`
Status *KubeDirectorClusterStatus `json:"status,omitempty"`
AppSpec *KubeDirectorApp `json:"-"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
137 changes: 128 additions & 9 deletions pkg/catalog/configmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,35 @@ import (
"sync"

kdv1 "github.com/bluek8s/kubedirector/pkg/apis/kubedirector/v1beta1"
"github.com/bluek8s/kubedirector/pkg/observer"
"github.com/bluek8s/kubedirector/pkg/shared"
v1 "k8s.io/api/core/v1"
)

const (
// ConfigMapType is a label placed on desired comfig maps that
// we want to watch and propogate inside containers
configMapType = shared.KdDomainBase + "/cmType"
)

// allServiceRefkeys is a subroutine of getServices, used to generate a
// description of a service's associated roles in the format expected by the
// app setup Python packages.
func allServiceRefkeys(
roleNames []string,
serviceName string,
connectedClusterName string,
) refkeysMap {

result := make(refkeysMap)
for _, r := range roleNames {
var refKeyList []string
if connectedClusterName != "" {
refKeyList = []string{"connections", "clusters", connectedClusterName}
}
refKeyList = append(refKeyList, "nodegroups", "1", "roles", r, "services", serviceName)
result[r] = refkeys{
BdvlibRefKey: []string{"nodegroups", "1", "roles", r, "services", serviceName},
BdvlibRefKey: refKeyList,
}
}
return result
Expand All @@ -47,6 +60,7 @@ func allServiceRefkeys(
func getServices(
appCR *kdv1.KubeDirectorApp,
membersForRole map[string][]*kdv1.MemberStatus,
connectedClusterName string,
) map[string]ngRefkeysMap {

result := make(map[string]ngRefkeysMap)
Expand All @@ -62,7 +76,7 @@ func getServices(
}
if len(activeRoleNames) > 0 {
result[service.ID] = ngRefkeysMap{
"1": allServiceRefkeys(activeRoleNames, service.ID),
"1": allServiceRefkeys(activeRoleNames, service.ID, connectedClusterName),
}
}
}
Expand All @@ -76,6 +90,8 @@ func servicesForRole(
appCR *kdv1.KubeDirectorApp,
roleName string,
members []*kdv1.MemberStatus,
connectedClusterName string,
domain string,
) map[string]service {

result := make(map[string]service)
Expand All @@ -89,7 +105,7 @@ func servicesForRole(
for _, m := range members {
nodeName := m.Pod
endpoint := serviceDef.Endpoint.URLScheme
endpoint += "://" + nodeName
endpoint += "://" + nodeName + "." + domain
endpoint += ":" + strconv.Itoa(int(*(serviceDef.Endpoint.Port)))
endpoints = append(endpoints, endpoint)
}
Expand All @@ -105,9 +121,19 @@ func servicesForRole(
FQDNs: refkeys{
BdvlibRefKey: []string{"nodegroups", "1", "roles", roleName, "fqdns"},
},
ExportedService: "", // currently, always empty
ExportedService: serviceDef.ExportedService,
Endpoints: endpoints,
}
if connectedClusterName != "" {
s.Hostnames.BdvlibRefKey = append(
[]string{"connections", "clusters", connectedClusterName},
s.Hostnames.BdvlibRefKey...,
)
s.FQDNs.BdvlibRefKey = append(
[]string{"connections", "clusters", connectedClusterName},
s.FQDNs.BdvlibRefKey...,
)
}
result[serviceDef.ID] = s
}
}
Expand All @@ -116,6 +142,85 @@ func servicesForRole(
return result
}

// genconfigConnections will look at the cluster spec
// and generates a map of configmap type and corresponding
// configmaps to be connected to the given cluster
func genconfigConnections(
cr *kdv1.KubeDirectorCluster,
) (map[string]map[string]map[string]string, error) {

cmMap := make(map[string]map[string]string)
kdcm := make(map[string]map[string]map[string]string)
for _, connectedCmName := range cr.Spec.Connections.ConfigMaps {
cm, err := observer.GetConfigMap(cr.Namespace, connectedCmName)
if kdConfigMapType, ok := cm.Labels[configMapType]; ok {
cmMap[connectedCmName] = cm.Data
kdcm[kdConfigMapType] = cmMap
if err != nil {
return nil, err
}
}
}
return kdcm, nil
}

// genClusterConnections generates a map of running clusters that are to be connected
// to this cluster.
func genClusterConnections(
cr *kdv1.KubeDirectorCluster,
) (map[string]configmeta, error) {

toConnectMeta := make(map[string]configmeta)
for _, clusterName := range cr.Spec.Connections.Clusters {
// Fetch the cluster object
clusterToConnect, connectedErr := observer.GetCluster(cr.Namespace, clusterName)
if connectedErr != nil {
return nil, connectedErr
}
appForclusterToConnect, connectedAppErr := observer.GetApp(clusterToConnect.Namespace, clusterToConnect.Spec.AppID)
if connectedAppErr != nil {
return nil, connectedAppErr
}
domain := clusterToConnect.Status.ClusterService + "." + clusterToConnect.Namespace + shared.GetSvcClusterDomainBase()
membersForRole := make(map[string][]*kdv1.MemberStatus)
for _, roleInfo := range clusterToConnect.Status.Roles {
var membersStatus []*kdv1.MemberStatus
for _, members := range roleInfo.Members {
membersStatus = append(
membersStatus,
&members,
)
}
membersForRole[roleInfo.Name] = membersStatus
}

toConnectMeta[clusterName] = configmeta{
Version: strconv.Itoa(appForclusterToConnect.Spec.SchemaVersion),
Services: getServices(appForclusterToConnect, membersForRole, clusterName),
Nodegroups: nodegroups(clusterToConnect, appForclusterToConnect, membersForRole, domain),
Distros: map[string]refkeysMap{
appForclusterToConnect.Spec.DistroID: refkeysMap{
"1": refkeys{
BdvlibRefKey: []string{"connections", "clusters", clusterName, "nodegroups", "1"},
},
},
},
Cluster: cluster{
Name: clusterName,
Isolated: false, // currently, always false
ID: string(clusterToConnect.UID),
ConfigMeta: map[string]refkeys{
"1": refkeys{
BdvlibRefKey: []string{"nodegroups", "1", "config_metadata"},
},
},
},
}
}

return toConnectMeta, nil
}

// nodegroups generates a map of nodegroup ID to internal nodegroup
// representation. Note that KubeDirector currently only allows/manages one
// nodegroup per virtual cluster, so this will always be a map that has a
Expand Down Expand Up @@ -157,7 +262,7 @@ func nodegroups(
Cores: strconv.FormatInt(coresQuant.Value(), 10), // rounds up
}
roles[roleName] = role{
Services: servicesForRole(appCR, roleName, members),
Services: servicesForRole(appCR, roleName, members, "", domain),
NodeIDs: nodeIds,
Hostnames: fqdns,
FQDNs: fqdns,
Expand All @@ -182,11 +287,21 @@ func clusterBaseConfig(
appCR *kdv1.KubeDirectorApp,
membersForRole map[string][]*kdv1.MemberStatus,
domain string,
) *configmeta {
) (*configmeta, error) {

clustersMeta, connErr := genClusterConnections(cr)
kdConfigMaps, cmErr := genconfigConnections(cr)

if cmErr != nil {
return nil, cmErr
}
if connErr != nil {
return nil, connErr
}

return &configmeta{
Version: strconv.Itoa(appCR.Spec.SchemaVersion),
Services: getServices(appCR, membersForRole),
Services: getServices(appCR, membersForRole, ""),
Nodegroups: nodegroups(cr, appCR, membersForRole, domain),
Distros: map[string]refkeysMap{
appCR.Spec.DistroID: refkeysMap{
Expand All @@ -205,7 +320,11 @@ func clusterBaseConfig(
},
},
},
}
Connections: connections{
Clusters: clustersMeta,
ConfigMaps: kdConfigMaps,
},
}, nil
}

// ConfigmetaGenerator returns a function that generates metadata which will be
Expand All @@ -230,7 +349,7 @@ func ConfigmetaGenerator(
// would be generated.
domain := cr.Status.ClusterService + "." + cr.Namespace + shared.GetSvcClusterDomainBase()
perNodeConfig := make(map[string]*node)
c := clusterBaseConfig(cr, appCR, membersForRole, domain)
c, _ := clusterBaseConfig(cr, appCR, membersForRole, domain)
for roleName, members := range membersForRole {
for _, member := range members {
memberName := member.Pod
Expand Down
18 changes: 12 additions & 6 deletions pkg/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ package catalog
// CR. It is arranged in a format to be consumed by the app setup Python
// packages.
type configmeta struct {
Version string `json:"version"`
Services map[string]ngRefkeysMap `json:"services"`
Nodegroups map[string]nodegroup `json:"nodegroups"`
Distros map[string]refkeysMap `json:"distros"`
Cluster cluster `json:"cluster"`
Node *node `json:"node"`
Version string `json:"version"`
Services map[string]ngRefkeysMap `json:"services"`
Nodegroups map[string]nodegroup `json:"nodegroups"`
Distros map[string]refkeysMap `json:"distros"`
Cluster cluster `json:"cluster"`
Node *node `json:"node"`
Connections connections `json:"connections"`
}

type ngRefkeysMap map[string]refkeysMap
Expand All @@ -42,6 +43,11 @@ type nodegroup struct {
ConfigMeta map[string]string `json:"config_metadata"`
}

type connections struct {
Clusters map[string]configmeta `json:"clusters"`
ConfigMaps map[string]map[string]map[string]string `json:"configmaps"`
}

type cluster struct {
Name string `json:"name"`
Isolated bool `json:"isolated"`
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/add_configmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package controller

import (
"github.com/bluek8s/kubedirector/pkg/controller/configmap"
)

func init() {

// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
AddToManagerFuncs = append(AddToManagerFuncs, configmap.Add)
}
Loading