some more fixes
This commit is contained in:
@ -7,11 +7,9 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
// "strings" // Not used
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
pb "git.dws.rip/dubey/kat/api/v1alpha1"
|
||||
"git.dws.rip/dubey/kat/internal/config"
|
||||
"git.dws.rip/dubey/kat/internal/leader"
|
||||
"git.dws.rip/dubey/kat/internal/store"
|
||||
@ -42,10 +40,9 @@ campaigns for leadership, and stores initial cluster configuration.`,
|
||||
)
|
||||
|
||||
const (
|
||||
clusterUIDKey = "/kat/config/cluster_uid"
|
||||
clusterConfigKey = "/kat/config/cluster_config" // Stores the JSON of pb.ClusterConfigurationSpec
|
||||
defaultNodeName = "kat-node"
|
||||
etcdDataDirDefault = "/var/lib/kat-agent/etcd"
|
||||
clusterUIDKey = "/kat/config/cluster_uid"
|
||||
clusterConfigKey = "/kat/config/cluster_config" // Stores the JSON of pb.ClusterConfigurationSpec
|
||||
defaultNodeName = "kat-node"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -69,14 +66,14 @@ func runInit(cmd *cobra.Command, args []string) {
|
||||
log.Fatalf("Failed to parse cluster configuration from %s: %v", clusterConfigPath, err)
|
||||
}
|
||||
// SetClusterConfigDefaults is already called within ParseClusterConfiguration in the provided internal/config/parse.go
|
||||
// config.SetClusterConfigDefaults(parsedClusterConfig)
|
||||
// config.SetClusterConfigDefaults(parsedClusterConfig)
|
||||
log.Printf("Successfully parsed and applied defaults to cluster configuration: %s", parsedClusterConfig.Metadata.Name)
|
||||
|
||||
// Prepare etcd embed config
|
||||
// For a single node init, this node is the only peer.
|
||||
// Client URLs and Peer URLs will be based on its own configuration.
|
||||
// Ensure ports are defaulted if not specified (SetClusterConfigDefaults handles this).
|
||||
|
||||
|
||||
// Assuming nodeName is resolvable or an IP is used. For simplicity, using localhost for single node.
|
||||
// In a multi-node setup, this needs to be the advertised IP.
|
||||
// For init, we assume this node is the first and only one.
|
||||
@ -84,11 +81,11 @@ func runInit(cmd *cobra.Command, args []string) {
|
||||
peerURL := fmt.Sprintf("http://localhost:%d", parsedClusterConfig.Spec.EtcdPeerPort)
|
||||
|
||||
etcdEmbedCfg := store.EtcdEmbedConfig{
|
||||
Name: nodeName, // Etcd member name
|
||||
DataDir: filepath.Join(etcdDataDirDefault, nodeName), // Ensure unique data dir
|
||||
ClientURLs: []string{clientURL}, // Listen on this for clients
|
||||
PeerURLs: []string{peerURL}, // Listen on this for peers
|
||||
InitialCluster: fmt.Sprintf("%s=%s", nodeName, peerURL), // For a new cluster, it's just itself
|
||||
Name: nodeName, // Etcd member name
|
||||
DataDir: filepath.Join(os.Getenv("HOME"), ".kat-agent", nodeName), // Ensure unique data dir
|
||||
ClientURLs: []string{clientURL}, // Listen on this for clients
|
||||
PeerURLs: []string{peerURL}, // Listen on this for peers
|
||||
InitialCluster: fmt.Sprintf("%s=%s", nodeName, peerURL), // For a new cluster, it's just itself
|
||||
// ForceNewCluster should be true if we are certain this is a brand new cluster.
|
||||
// For simplicity in init, we might not set it and rely on empty data-dir.
|
||||
// embed.Config has ForceNewCluster field.
|
||||
@ -141,7 +138,6 @@ func runInit(cmd *cobra.Command, args []string) {
|
||||
log.Printf("Cluster UID already exists in etcd. Skipping storage.")
|
||||
}
|
||||
|
||||
|
||||
// Store ClusterConfigurationSpec (as JSON)
|
||||
// We store Spec because Metadata might change (e.g. resourceVersion)
|
||||
// and is more for API object representation.
|
||||
@ -181,7 +177,6 @@ func runInit(cmd *cobra.Command, args []string) {
|
||||
leadershipMgr.LeaseTTLSeconds = leader.DefaultLeaseTTLSeconds
|
||||
}
|
||||
|
||||
|
||||
// Run leadership manager. This will block until ctx is cancelled.
|
||||
go leadershipMgr.Run(ctx)
|
||||
|
||||
@ -201,20 +196,3 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to check if a string is in a slice of strings (Not currently used)
|
||||
// func containsString(slice []string, s string) bool {
|
||||
// for _, item := range slice {
|
||||
// if item == s {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
// SanitizeClusterConfigForStorage can be used if we want to strip sensitive fields
|
||||
// or normalize the config before storing. For now, storing Spec as is.
|
||||
// func SanitizeClusterConfigForStorage(config *pb.ClusterConfiguration) *pb.ClusterConfigurationSpec {
|
||||
// // Example: return a copy with certain fields cleared if needed
|
||||
// return config.Spec
|
||||
// }
|
||||
|
Reference in New Issue
Block a user