upsert-resource
Insert a resource, or if the resource already exists, update the existing resource.
upsert-resource #
Overview #
Insert a resource, or if the resource already exists, update the existing resource.
FunctionConfig #
Upsert is an operation that adds a resource(uniquely identified by Group, Kind, Name and Namespace)
if it does not already exist, or replaces it if it already exists in the input list of resources.
upsert-resource
function offers a safe way to upsert a resource to the list of input resources.
Examples #
Replace an existing resource #
Let’s start with the list of resources in a package:
apiVersion: v1
kind: Service
metadata:
name: myService
namespace: mySpace
spec:
selector:
app: foo
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
namespace: mySpace
spec:
replicas: 3
Add a new resource #
For the same input resource list above, pass the following resource to upsert.
Note that the name of the resource is myService2
.
apiVersion: v1
kind: Service
metadata:
name: myService2
namespace: mySpace
spec:
selector:
app: bar
Invoking upsert-resource
function adds the input resource to the package.
apiVersion: v1
kind: Service
metadata:
name: myService
namespace: mySpace
spec:
selector:
app: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
namespace: mySpace
spec:
replicas: 3
---
apiVersion: v1
kind: Service
metadata:
name: myService2
namespace: mySpace
spec:
selector:
app: bar
Last modified October 9, 2025: Moving the documentation to Hugo (#1177) (a7f5458)