Skip to content

Commit

Permalink
fix: require label & field selector values (#18)
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
jeff-mccoy authored Oct 3, 2023
1 parent 3a29afe commit 678d6a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/fluent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export function K8s<T extends GenericClass, K extends KubernetesObject = Instanc
return withFilters;
}

function WithField<P extends Paths<K>>(key: P, value = "") {
function WithField<P extends Paths<K>>(key: P, value: string) {
filters.fields = filters.fields || {};
filters.fields[key] = value;
return withFilters;
}

function WithLabel(key: string, value = "") {
function WithLabel(key: string, value: string) {
filters.labels = filters.labels || {};
filters.labels[key] = value;
return withFilters;
Expand Down
6 changes: 4 additions & 2 deletions src/fluent/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
* ```
*
* Will only delete the Deployment if it has the `metadata.name=bar` and `metadata.namespace=qux` fields.
* Not all fields are supported, see https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/#supported-fields,
* but Typescript will limit to only fields that exist on the resource.
*
* @param key The field key
* @param value The field value
* @returns
*/
WithField: <P extends Paths<K>>(key: P, value?: string) => K8sWithFilters<K>;
WithField: <P extends Paths<K>>(key: P, value: string) => K8sWithFilters<K>;

/**
* Filter the query by the given label. If no value is specified, the label simply must exist.
Expand All @@ -122,7 +124,7 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
* @param key The label key
* @param value (optional) The label value
*/
WithLabel: (key: string, value?: string) => K8sWithFilters<K>;
WithLabel: (key: string, value: string) => K8sWithFilters<K>;
};

export type K8sInit<K extends KubernetesObject> = K8sWithFilters<K> &
Expand Down

0 comments on commit 678d6a3

Please sign in to comment.