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

fix(kernel_crawler): fixed bottlerocket crawler. #199

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
88 changes: 55 additions & 33 deletions kernel_crawler/bottlerocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def extract_flavor(self, flavorconfig_path):
return re.match(r"^config-bottlerocket-(.*)", flavorconfig_file).group(1)

def extract_kver(self, kverspec_file):
return re.match(r"^kernel-(.*).spec", kverspec_file).group(1)
return re.match(r"^kernel-(.*).spec$", kverspec_file).group(1)

def set_kernel_config(self, baseconfig, key, value):
for i, line in enumerate(baseconfig):
Expand Down Expand Up @@ -90,52 +90,74 @@ def get_package_tree(self, version=''):
self.checkout_version(v)

# Find supported kernels dynamically
supported_kernel_specs = self.match_file("kernel-.*.spec", False)
supported_kernel_specs = self.match_file("kernel-.*.spec", True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetch the full path to kernel specs, so that we can use their dirname as working dir when looking up for config file and supported flavors.
This is a fix.

for kverspec_file in supported_kernel_specs:
kver = self.extract_kver(kverspec_file)
name = os.path.basename(kverspec_file)
wd = os.path.dirname(kverspec_file)
kver = self.extract_kver(name)

# same meaning as the output of "uname -r"
kernel_release = self.extract_value(kverspec_file, "Version", ":")
if kernel_release is None:
continue

# Load base config
baseconfig = self.fetch_base_config(kverspec_file)
if baseconfig is None:
vanillaconfig = self.fetch_base_config(kverspec_file)
if vanillaconfig is None:
continue

# Load common config
commonconfig_file = self.search_file("config-bottlerocket")
if commonconfig_file is None:
specific_config_file = self.search_file("config-bottlerocket", wd)
if specific_config_file is None:
continue
with open(commonconfig_file, 'r') as fd:
commonconfig = fd.readlines()

with open(specific_config_file, 'r') as fd:
specific_config = fd.readlines()

# Find supported flavors dynamically
supported_flavors = self.match_file("config-bottlerocket-.*")
for flavorconfig_file in supported_flavors:
flavor = self.extract_flavor(flavorconfig_file)

# Load flavor specific config
with open(flavorconfig_file, 'r') as fd:
flavorconfig = fd.readlines()

# Merge flavor and common config
flavorconfig += commonconfig

# Finally, patch baseconfig with flavor config
finalconfig = self.patch_config(baseconfig, flavorconfig)
defconfig_base64 = base64.b64encode(b''.join(finalconfig)).decode()

kernel_version = "1_" + v + "-" + flavor

# Unique key
kernel_configs[v + "_" + kver + "-" + flavor] = {
self.KERNEL_VERSION: kernel_version,
self.KERNEL_RELEASE: kernel_release,
self.DISTRO_TARGET: "bottlerocket",
self.BASE_64_CONFIG_DATA: defconfig_base64,
}
supported_flavors = self.match_file("config-bottlerocket-.*", True, wd)
if supported_flavors:
for flavorconfig_file in supported_flavors:
flavor = self.extract_flavor(flavorconfig_file)

# Load flavor specific config
with open(flavorconfig_file, 'r') as fd:
flavorconfig = fd.readlines()

# Merge flavor and common config
flavorconfig += specific_config

# Finally, patch baseconfig with flavor config
finalconfig = self.patch_config(vanillaconfig, flavorconfig)
defconfig_base64 = base64.b64encode(b''.join(finalconfig)).decode()

kernel_version = "1_" + v + "-" + flavor

# Unique key
kernel_configs[v + "_" + kver + "-" + flavor] = {
self.KERNEL_VERSION: kernel_version,
self.KERNEL_RELEASE: kernel_release,
self.DISTRO_TARGET: "bottlerocket",
self.BASE_64_CONFIG_DATA: defconfig_base64,
}
else:
# NOTE: to keep backward compatibility with existing drivers
# and driver loader logic, push these kernels for each flavor
# even if the config is the same among all of them.
# We will build 3x the drivers but we will be backward compatible.
for flavor in ['aws','metal','vmware']:
finalconfig = self.patch_config(vanillaconfig, specific_config)
defconfig_base64 = base64.b64encode(b''.join(finalconfig)).decode()

kernel_version = "1_" + v + "-" + flavor

# Unique key
kernel_configs[v + "_" + kver + "-" + flavor] = {
self.KERNEL_VERSION: kernel_version,
self.KERNEL_RELEASE: kernel_release,
self.DISTRO_TARGET: "bottlerocket",
self.BASE_64_CONFIG_DATA: defconfig_base64,
}

bar.update(1)
bar.render_finish()
Expand Down
20 changes: 13 additions & 7 deletions kernel_crawler/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def cleanup_repo(self):
shutil.rmtree(self.repo.workdir, True)

def getVersions(self, last_n=0):
re_tags = re.compile('^refs/tags/v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)$')
re_tags = re.compile(r'^refs/tags/v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)$')

all_versions = [os.path.basename(v).strip('v') for v in self.repo.references if re_tags.match(v)]
all_versions.sort(key=SemVersion)
Expand Down Expand Up @@ -97,16 +97,20 @@ def checkout_hash(self, commithash):

return self.checkout_version(commithash)

def search_file(self, file_name):
for dirpath, dirnames, files in os.walk(self.repo.workdir):
def search_file(self, file_name, wd=''):
if wd == '':
wd = self.repo.workdir
for dirpath, dirnames, files in os.walk(wd):
for name in files:
if name == file_name:
return os.path.join(dirpath, name)
return None

def match_file(self, pattern, fullpath=True):
def match_file(self, pattern, fullpath=True, wd=''):
matches = []
for dirpath, dirnames, files in os.walk(self.repo.workdir):
if wd == '':
wd = self.repo.workdir
for dirpath, dirnames, files in os.walk(wd):
for name in files:
if re.search(r'^'+pattern, name):
if fullpath:
Expand All @@ -116,8 +120,10 @@ def match_file(self, pattern, fullpath=True):
return matches

def extract_value(self, file_name, key, sep):
# here kernel release is the same as the one given by "uname -r"
full_path = self.search_file(file_name)
if os.path.isabs(file_name):
full_path = file_name
else:
full_path = self.search_file(file_name)
for line in open(full_path):
stripped_line = line.lstrip()
if re.search(r'^'+key + sep, stripped_line):
Expand Down
Loading