Add inserts an object into a deployment. The object must be a valid Kubernetes object or it will fail. There can only be a single object of the same name, namespace, and type. Objects are deep-copied into the Deployment.
(obj KubeObject)
| 40 | // Add inserts an object into a deployment. The object must be a valid Kubernetes object or it will fail. |
| 41 | // There can only be a single object of the same name, namespace, and type. Objects are deep-copied into the Deployment. |
| 42 | func (d *Deployment) Add(obj KubeObject) error { |
| 43 | // create objects if doesn't exist |
| 44 | if d.objects == nil { |
| 45 | d.objects = make(map[string]KubeObject, 1) |
| 46 | } |
| 47 | |
| 48 | // generate path using meta and type info |
| 49 | path, err := ObjectPath(obj) |
| 50 | if err != nil { |
| 51 | return fmt.Errorf("could not add object: %v", err) |
| 52 | } |
| 53 | |
| 54 | // there can only be one object per path |
| 55 | if _, exists := d.objects[path]; exists { |
| 56 | return ErrorConflict |
| 57 | } |
| 58 | |
| 59 | // create a copy of values |
| 60 | copy, err := deepCopy(obj) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | // add object to |
| 66 | d.objects[path] = copy |
| 67 | return nil |
| 68 | } |
| 69 | |
| 70 | // AddDeployment inserts the contents of one Deployment into another. |
| 71 | func (d *Deployment) AddDeployment(deployment Deployment) (err error) { |