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

feat(manager/helm-values): add image support in helm values manager #29828

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Default values for test-chart.
Copy link
Member

Choose a reason for hiding this comment

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

Reduce to minimal size and inline to test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean to inline? i should remove the file and pass the values in the test ?

Copy link
Member

Choose a reason for hiding this comment

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

yes

# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repo: nginx
tag: 1.16.1
pullPolicy: IfNotPresent

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
# Specifies whether a service account should be created
create: true
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name:

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 80

ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []

tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}
13 changes: 13 additions & 0 deletions lib/modules/manager/helm-values/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const helmMultiAndNestedImageValues = Fixtures.get(
'multi_and_nested_image_values.yaml',
);

const helmImageInsteadOfRepository = Fixtures.get(
'values_with_image_instead_of_repo.yaml',
);

Comment on lines +14 to +17
Copy link
Member

Choose a reason for hiding this comment

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

inline to test

const config = partial<ExtractConfig>({});

const configAliases = partial<ExtractConfig>({
Expand Down Expand Up @@ -108,5 +112,14 @@ describe('modules/manager/helm-values/extract', () => {
],
});
});

it('return null if image and repo are not defined', () => {
const result = extractPackageFile(
helmImageInsteadOfRepository,
packageFile,
config,
);
expect(result).toBeNull();
});
});
});
10 changes: 8 additions & 2 deletions lib/modules/manager/helm-values/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@
Object.entries(parsedContent).forEach(([key, value]) => {
if (matchesHelmValuesDockerHeuristic(key, value)) {
const currentItem = value;

let registry = currentItem.registry;
registry = registry ? `${registry}/` : '';
const repository = String(currentItem.repository);
if (
currentItem.repository === undefined &&
currentItem.image === undefined
) {
logger.debug('repository and image are both undefined');
KyriosGN0 marked this conversation as resolved.
Show resolved Hide resolved
return null;

Check warning on line 58 in lib/modules/manager/helm-values/extract.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/manager/helm-values/extract.ts#L57-L58

Added lines #L57 - L58 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

needs a test

}
const repository = `${currentItem.repository ?? currentItem.image}`;
const tag = `${currentItem.tag ?? currentItem.version}`;
packageDependencies.push(getHelmDep(registry, repository, tag, config));
} else if (matchesHelmValuesInlineImage(key, value)) {
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/manager/helm-values/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ image:
repository: 'some-docker/dependency'
version: v1.0.0

image:
image: 'some-docker/dependency'
version: v1.0.0

coreImage:
registry: docker.io
repository: bitnami/harbor-core
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/helm-values/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface HelmDockerImageDependencyBasic {
registry?: string;
repository: string;
repository?: string;
image?: string;
}

export interface HelmDockerImageDependencyTag
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/helm-values/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function matchesHelmValuesDockerHeuristic(
parentKeyRe.test(parentKey) &&
data &&
typeof data === 'object' &&
hasKey('repository', data) &&
(hasKey('repository', data) || hasKey('image', data)) &&
(hasKey('tag', data) || hasKey('version', data))
);
}
Expand Down
Loading