community
community copied to clipboard
Expand FieldExport to support json `path` to target arbitrary fields of matching GNKV resources
Is your feature request related to a problem? Kustomize replacements/patches provide a means to modify specific attributes in a k8s resource via a json path. Field Exports enhanced with this capability could provide new functionality beyond targeting configMap/secrets.
For example, services of type externalName
create a local DNS entry for connecting to services by a short name within the cluster.
FieldExport can be enhanced to update spec.externalName
of a Service so that this DNS entry is dynamically updated to match newly created AWS resources.
Describe the solution you'd like
apiVersion: services.k8s.aws/v1alpha1
kind: FieldExport
metadata:
name: postgres-rds
spec:
from:
resource:
kind: DBInstance
name: postgres
path: ".status.endpoint.port"
to:
kind: Service
name: postgres-rds
path: "spec.externalName"
Describe alternatives you've considered
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres-init-rds-endpoint
spec:
replicas: 1
selector:
matchLabels:
name: postgres-init-rds-endpoint
template:
metadata:
labels:
name: postgres-init-rds-endpoint
spec:
serviceAccountName: postgres
containers:
- name: postgres-init-rds-endpoint
image: ansible:latest
env:
- name: DBINSTANCE
value: postgres
- name: SERVICE
value: postgres-rds
command:
- /bin/sh
- -c
- |-
get_rds_endpoint() { kubectl get "dbinstance/${DBINSTANCE}" -o json | yq -P e .status.endpoint.address - ; }
get_service_endpoint() { kubectl get -o yaml "service/${SERVICE}" | yq e '.spec.externalName' - ; }
set -x
while sleep 7 ; do
RDS_ENDPOINT="$(get_rds_endpoint)"
SERVICE_ENDPOINT="$(get_service_endpoint)"
case "${RDS_ENDPOINT}" in
null|"${SERVICE_ENDPOINT}") :;;
*) kubectl patch --type merge "service/${SERVICE}" -p "{ \"spec\": { \"externalName\": \"${RDS_ENDPOINT}\" } }";;
esac
done