upsert-resource
Overview
Insert a resource, or if the resource already exists, update the existing resource.
FunctionConfig
Upsert is an operation that adds resources(uniquely identified by Group, Kind, Name, Namespace and Path)
if they do not already exist, or replaces them if they already exist in the input list of resources.
upsert-resource
function offers a safe way to upsert a resources 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
Resource to upsert:
apiVersion: v1
kind: Service
metadata:
name: myService
namespace: mySpace
spec:
selector:
app: bar
Invoking upsert-resource
function replaces the resource with name myService
:
apiVersion: v1
kind: Service
metadata:
name: myService
namespace: mySpace
spec:
selector:
app: bar
---
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