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

handle stringification the same way for all vpc-cni configuration pro… #1048

Merged
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
31 changes: 20 additions & 11 deletions lib/addons/vpc-cni/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,23 @@ export class VpcCniAddOn extends CoreAddOn {
}
}

/**
* Iterates over all values including nested child objects, removes undefined entries and stringifies the remaining if they are not already strings
*/
function ConvertPropertiesToString(helmValues: Values): void {
Object.keys(helmValues).forEach(key => {
if (helmValues[key] === undefined) {
delete helmValues[key];
}
else if (typeof helmValues[key] === 'object'){
ConvertPropertiesToString(helmValues[key]);
}
else if (typeof helmValues[key] !== 'string'){
helmValues[key] = JSON.stringify(helmValues[key]);
}
});
}

function populateVpcCniConfigurationValues(props?: VpcCniAddOnProps): Values {
if (props === null) {
return {};
Expand Down Expand Up @@ -449,19 +466,11 @@ function populateVpcCniConfigurationValues(props?: VpcCniAddOnProps): Values {
WARM_IP_TARGET: props?.warmIpTarget,
WARM_PREFIX_TARGET: props?.warmPrefixTarget,
},
enableNetworkPolicy: JSON.stringify(props?.enableNetworkPolicy),
enableWindowsIpam: JSON.stringify(props?.enableWindowsIpam)
enableNetworkPolicy: props?.enableNetworkPolicy,
enableWindowsIpam: props?.enableWindowsIpam
};

// clean up all undefined
const values = result.env;
Object.keys(values).forEach(key => values[key] === undefined ? delete values[key] : {});
Object.keys(values).forEach(key => values[key] = typeof values[key] !== 'string' ? JSON.stringify(values[key]) : values[key]);

// clean up all undefined on Init env
const initValues = result.init.env;
Object.keys(initValues).forEach(key => initValues[key] === undefined ? delete initValues[key] : {});
Object.keys(initValues).forEach(key => initValues[key] = typeof initValues[key] !== 'string' ? JSON.stringify(initValues[key]) : initValues[key]);
ConvertPropertiesToString(result);

return result;
}
Loading