33Kube-Stack Version Update Script
44
55This script automatically updates the kube-stack version in the docset.yml file
6- by fetching the latest version from the elastic-agent repository.
6+ by fetching the latest collector version from elastic-agent repository tags
7+ and then retrieving the corresponding kube-stack version.
78
89Usage:
910 python update_kube_stack_version.py [--dry-run]
1617import re
1718import sys
1819import argparse
20+ import subprocess
1921from pathlib import Path
2022
2123
@@ -31,27 +33,53 @@ def fetch_url_content(url):
3133 return None
3234
3335
34- def get_collector_version ( file_path ):
35- """Extract the collector version from docset.yml """
36+ def get_latest_collector_version ( ):
37+ """Get the latest semantic version from elastic-agent repository tags """
3638 try :
37- with open (file_path , 'r' , encoding = 'utf-8' ) as file :
38- content = file .read ()
39+ print ("Fetching latest collector version from elastic-agent repository..." )
40+
41+ # Run git command to get the latest semantic version tag
42+ cmd = ['git' , 'ls-remote' , '--tags' , 'https://github.com/elastic/elastic-agent.git' ]
43+ result = subprocess .run (cmd , capture_output = True , text = True , check = True )
44+
45+ # Extract version tags and find the latest semantic version
46+ tags = []
47+ for line in result .stdout .splitlines ():
48+ if 'refs/tags/v' in line :
49+ tag = line .split ('refs/tags/' )[- 1 ]
50+ # Match semantic version pattern (vX.Y.Z)
51+ if re .match (r'^v[0-9]+\.[0-9]+\.[0-9]+$' , tag ):
52+ tags .append (tag )
53+
54+ if not tags :
55+ print ("No semantic version tags found" )
56+ return None
3957
40- lines = content .splitlines ()
41- for line in lines :
42- if line .strip ().startswith ('edot-collector-version:' ):
43- return line .split (':' , 1 )[1 ].strip ()
58+ # Sort tags by version and get the latest
59+ def version_key (tag ):
60+ # Remove 'v' prefix and split by dots
61+ version_parts = tag [1 :].split ('.' )
62+ return tuple (int (part ) for part in version_parts )
63+
64+ latest_tag = max (tags , key = version_key )
65+ version = latest_tag [1 :] # Remove 'v' prefix
4466
45- # If no specific version is found, use a default version that we know works
46- return '9.1.2'
47- except FileNotFoundError :
48- print (f"Error: Could not find { file_path } " )
67+ print (f"Latest collector version: { version } " )
68+ return version
69+
70+ except subprocess .CalledProcessError as e :
71+ print (f"Error fetching tags from elastic-agent repository: { e } " )
4972 return None
5073 except Exception as e :
51- print (f"Error reading { file_path } : { e } " )
74+ print (f"Error getting latest collector version : { e } " )
5275 return None
5376
5477
78+ def get_collector_version ():
79+ """Get the latest collector version from elastic-agent repository tags"""
80+ return get_latest_collector_version ()
81+
82+
5583def get_kube_stack_version (version = 'main' ):
5684 """Extract KubeStackChartVersion from elastic-agent repository"""
5785 # Try different URL formats for the k8s.go file
@@ -130,8 +158,8 @@ def main():
130158
131159 print (f"Using docset.yml path: { docset_path } " )
132160
133- # Get the current collector version from docset.yml
134- col_version = get_collector_version (docset_path )
161+ # Get the latest collector version from elastic-agent repository
162+ col_version = get_collector_version ()
135163 if col_version is None :
136164 print ("Error: Could not determine collector version" )
137165 sys .exit (1 )
@@ -153,8 +181,8 @@ def main():
153181 print ("Kube-stack version update completed successfully" )
154182 sys .exit (0 )
155183 else :
156- print ("No update was needed or update failed " )
157- sys .exit (1 )
184+ print ("No update was needed" )
185+ sys .exit (0 )
158186
159187
160188if __name__ == '__main__' :
0 commit comments