@@ -17,6 +17,7 @@ import (
1717)
1818
1919var clusterIDMut sync.Mutex
20+ var clusterID * uuid.UUID
2021
2122// BaseURL determines the base url to be used when sending metrics over.
2223func BaseURL (license * kotsv1beta1.License ) string {
@@ -43,30 +44,15 @@ func License(c *cli.Context) *kotsv1beta1.License {
4344 return license
4445}
4546
46- // ClusterID returns the cluster id. It is read from from a local file (if this is
47- // a second attempt at installation or an upgrade) or a new one is generated and
48- // stored locally.
47+ // ClusterID returns the cluster id. This is unique per 'install', but will be stored in the cluster and used by any future 'join' commands.
4948func ClusterID () uuid.UUID {
5049 clusterIDMut .Lock ()
5150 defer clusterIDMut .Unlock ()
52- fpath := defaults .PathToConfig (".cluster-id" )
53- if _ , err := os .Stat (fpath ); err == nil {
54- data , err := os .ReadFile (fpath )
55- if err != nil {
56- logrus .Warnf ("unable to read cluster id from %s: %s" , fpath , err )
57- return uuid .New ()
58- }
59- id , err := uuid .Parse (string (data ))
60- if err != nil {
61- logrus .Warnf ("unable to parse cluster id from %s: %s" , fpath , err )
62- return uuid .New ()
63- }
64- return id
51+ if clusterID != nil {
52+ return * clusterID
6553 }
6654 id := uuid .New ()
67- if err := os .WriteFile (fpath , []byte (id .String ()), 0644 ); err != nil {
68- logrus .Warnf ("unable to write cluster id to %s: %s" , fpath , err )
69- }
55+ clusterID = & id
7056 return id
7157}
7258
0 commit comments