@ -220,7 +220,6 @@ func ClusterPrep(ctx context.Context, runtime k3drt.Runtime, clusterConfig *conf
} )
} )
registryConfig = regConf
registryConfig = regConf
}
}
// merge with pre-existing, referenced registries.yaml
// merge with pre-existing, referenced registries.yaml
if clusterConfig . ClusterCreateOpts . Registries . Config != nil {
if clusterConfig . ClusterCreateOpts . Registries . Config != nil {
@ -251,7 +250,6 @@ func ClusterPrep(ctx context.Context, runtime k3drt.Runtime, clusterConfig *conf
}
}
return nil
return nil
}
}
// ClusterPrepNetwork creates a new cluster network, if needed or sets everything up to re-use an existing network
// ClusterPrepNetwork creates a new cluster network, if needed or sets everything up to re-use an existing network
@ -332,7 +330,6 @@ func ClusterPrepImageVolume(ctx context.Context, runtime k3drt.Runtime, cluster
// - some containerized k3s nodes
// - some containerized k3s nodes
// - a docker network
// - a docker network
func ClusterCreate ( ctx context . Context , runtime k3drt . Runtime , cluster * k3d . Cluster , clusterCreateOpts * k3d . ClusterCreateOpts ) error {
func ClusterCreate ( ctx context . Context , runtime k3drt . Runtime , cluster * k3d . Cluster , clusterCreateOpts * k3d . ClusterCreateOpts ) error {
l . Log ( ) . Tracef ( `
l . Log ( ) . Tracef ( `
== == = Creating Cluster == == =
== == = Creating Cluster == == =
@ -431,7 +428,6 @@ ClusterCreatOpts:
// node role specific settings
// node role specific settings
if node . Role == k3d . ServerRole {
if node . Role == k3d . ServerRole {
if cluster . Network . IPAM . Managed {
if cluster . Network . IPAM . Managed {
ip , err := GetIP ( ctx , runtime , & cluster . Network )
ip , err := GetIP ( ctx , runtime , & cluster . Network )
if err != nil {
if err != nil {
@ -450,7 +446,6 @@ ClusterCreatOpts:
node . Env = append ( node . Env , fmt . Sprintf ( "%s=%s" , k3s . EnvClusterConnectURL , connectionURL ) )
node . Env = append ( node . Env , fmt . Sprintf ( "%s=%s" , k3s . EnvClusterConnectURL , connectionURL ) )
node . RuntimeLabels [ k3d . LabelServerIsInit ] = "false" // set label, that this server node is not the init server
node . RuntimeLabels [ k3d . LabelServerIsInit ] = "false" // set label, that this server node is not the init server
}
}
} else if node . Role == k3d . AgentRole {
} else if node . Role == k3d . AgentRole {
node . Env = append ( node . Env , fmt . Sprintf ( "%s=%s" , k3s . EnvClusterConnectURL , connectionURL ) )
node . Env = append ( node . Env , fmt . Sprintf ( "%s=%s" , k3s . EnvClusterConnectURL , connectionURL ) )
}
}
@ -492,13 +487,11 @@ ClusterCreatOpts:
return fmt . Errorf ( "failed init node setup: %w" , err )
return fmt . Errorf ( "failed init node setup: %w" , err )
}
}
serverCount ++
serverCount ++
}
}
// create all other nodes, but skip the init node
// create all other nodes, but skip the init node
for _ , node := range cluster . Nodes {
for _ , node := range cluster . Nodes {
if node . Role == k3d . ServerRole {
if node . Role == k3d . ServerRole {
// skip the init node here
// skip the init node here
if node == cluster . InitNode {
if node == cluster . InitNode {
continue
continue
@ -513,7 +506,6 @@ ClusterCreatOpts:
time . Sleep ( 1 * time . Second ) // FIXME: arbitrary wait for one second to avoid race conditions of servers registering
time . Sleep ( 1 * time . Second ) // FIXME: arbitrary wait for one second to avoid race conditions of servers registering
serverCount ++
serverCount ++
}
}
if node . Role == k3d . ServerRole || node . Role == k3d . AgentRole {
if node . Role == k3d . ServerRole || node . Role == k3d . AgentRole {
if err := nodeSetup ( node ) ; err != nil {
if err := nodeSetup ( node ) ; err != nil {
@ -589,7 +581,6 @@ ClusterCreatOpts:
// ClusterDelete deletes an existing cluster
// ClusterDelete deletes an existing cluster
func ClusterDelete ( ctx context . Context , runtime k3drt . Runtime , cluster * k3d . Cluster , opts k3d . ClusterDeleteOpts ) error {
func ClusterDelete ( ctx context . Context , runtime k3drt . Runtime , cluster * k3d . Cluster , opts k3d . ClusterDeleteOpts ) error {
l . Log ( ) . Infof ( "Deleting cluster '%s'" , cluster . Name )
l . Log ( ) . Infof ( "Deleting cluster '%s'" , cluster . Name )
cluster , err := ClusterGet ( ctx , runtime , cluster )
cluster , err := ClusterGet ( ctx , runtime , cluster )
if err != nil {
if err != nil {
@ -641,7 +632,6 @@ func ClusterDelete(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clus
l . Log ( ) . Infof ( "Deleting cluster network '%s'" , cluster . Network . Name )
l . Log ( ) . Infof ( "Deleting cluster network '%s'" , cluster . Network . Name )
if err := runtime . DeleteNetwork ( ctx , cluster . Network . Name ) ; err != nil {
if err := runtime . DeleteNetwork ( ctx , cluster . Network . Name ) ; err != nil {
if errors . Is ( err , runtimeErr . ErrRuntimeNetworkNotEmpty ) { // there are still containers connected to that network
if errors . Is ( err , runtimeErr . ErrRuntimeNetworkNotEmpty ) { // there are still containers connected to that network
connectedNodes , err := runtime . GetNodesInNetwork ( ctx , cluster . Network . Name ) // check, if there are any k3d nodes connected to the cluster
connectedNodes , err := runtime . GetNodesInNetwork ( ctx , cluster . Network . Name ) // check, if there are any k3d nodes connected to the cluster
if err != nil {
if err != nil {
l . Log ( ) . Warningf ( "Failed to check cluster network for connected nodes: %+v" , err )
l . Log ( ) . Warningf ( "Failed to check cluster network for connected nodes: %+v" , err )
@ -751,7 +741,6 @@ func populateClusterFieldsFromLabels(cluster *k3d.Cluster) error {
networkExternalSet := false
networkExternalSet := false
for _ , node := range cluster . Nodes {
for _ , node := range cluster . Nodes {
// get the name of the cluster network
// get the name of the cluster network
if cluster . Network . Name == "" {
if cluster . Network . Name == "" {
if networkName , ok := node . RuntimeLabels [ k3d . LabelNetwork ] ; ok {
if networkName , ok := node . RuntimeLabels [ k3d . LabelNetwork ] ; ok {
@ -820,11 +809,9 @@ func ClusterGet(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Cluster
// append nodes
// append nodes
for _ , node := range nodes {
for _ , node := range nodes {
// check if there's already a node in the struct
// check if there's already a node in the struct
overwroteExisting := false
overwroteExisting := false
for _ , existingNode := range cluster . Nodes {
for _ , existingNode := range cluster . Nodes {
// overwrite existing node
// overwrite existing node
if existingNode . Name == node . Name {
if existingNode . Name == node . Name {
mergo . MergeWithOverwrite ( existingNode , node )
mergo . MergeWithOverwrite ( existingNode , node )
@ -836,7 +823,6 @@ func ClusterGet(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Cluster
if ! overwroteExisting {
if ! overwroteExisting {
cluster . Nodes = append ( cluster . Nodes , node )
cluster . Nodes = append ( cluster . Nodes , node )
}
}
}
}
// Loadbalancer
// Loadbalancer
@ -1018,7 +1004,6 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
* /
* /
if len ( servers ) > 0 || len ( agents ) > 0 { // TODO: make checks for required cluster start actions cleaner
if len ( servers ) > 0 || len ( agents ) > 0 { // TODO: make checks for required cluster start actions cleaner
postStartErrgrp , postStartErrgrpCtx := errgroup . WithContext ( ctx )
postStartErrgrp , postStartErrgrpCtx := errgroup . WithContext ( ctx )
/*** DNS ***/
/*** DNS ***/
@ -1044,7 +1029,6 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
// -> inject hostAliases and network members into CoreDNS configmap
// -> inject hostAliases and network members into CoreDNS configmap
if len ( servers ) > 0 {
if len ( servers ) > 0 {
postStartErrgrp . Go ( func ( ) error {
postStartErrgrp . Go ( func ( ) error {
hosts := ""
hosts := ""
// hosts: hostAliases (including host.k3d.internal)
// hosts: hostAliases (including host.k3d.internal)
@ -1101,7 +1085,6 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
// get the first server in the list and run action on it once it's ready for it
// get the first server in the list and run action on it once it's ready for it
for _ , n := range servers {
for _ , n := range servers {
// do not try to run the action, if CoreDNS is disabled on K3s level
// do not try to run the action, if CoreDNS is disabled on K3s level
for _ , flag := range n . Args {
for _ , flag := range n . Args {
if strings . HasPrefix ( flag , "--disable" ) && strings . Contains ( flag , "coredns" ) {
if strings . HasPrefix ( flag , "--disable" ) && strings . Contains ( flag , "coredns" ) {