This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement ResourceStore to abstract out manifest operations. ResourceStore is meant to abstract out file operations on explicit manifest files, paving the way for supporting programatically-generated cluster resources. * Implement flux configfile parsing and execution
- Loading branch information
Showing
22 changed files
with
886 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,36 @@ | ||
package cluster | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/weaveworks/flux" | ||
"github.com/weaveworks/flux/image" | ||
"github.com/weaveworks/flux/policy" | ||
"github.com/weaveworks/flux/resource" | ||
) | ||
|
||
type ManifestError struct { | ||
error | ||
} | ||
|
||
func ErrResourceNotFound(name string) error { | ||
return ManifestError{fmt.Errorf("manifest for resource %s not found under manifests path", name)} | ||
// An Annotation change indicates how an annotation should be changed | ||
type AnnotationChange struct { | ||
AnnotationKey string | ||
// AnnotationValue is the value to set the anntoation to, nil indicates delete | ||
AnnotationValue *string | ||
} | ||
|
||
// Manifests represents how a set of files are used as definitions of | ||
// Manifests represents a set of files containing definitions of | ||
// resources, e.g., in Kubernetes, YAML files describing Kubernetes | ||
// resources. | ||
type Manifests interface { | ||
// Update the image in a manifest's bytes to that given | ||
UpdateImage(def []byte, resourceID flux.ResourceID, container string, newImageID image.Ref) ([]byte, error) | ||
// Load all the resource manifests under the paths | ||
// given. `baseDir` is used to relativise the paths, which are | ||
// supplied as absolute paths to directories or files; at least | ||
// one path should be supplied, even if it is the same as `baseDir`. | ||
LoadManifests(baseDir string, paths []string) (map[string]resource.Resource, error) | ||
// UpdatePolicies modifies a manifest to apply the policy update specified | ||
UpdatePolicies([]byte, flux.ResourceID, policy.Update) ([]byte, error) | ||
} | ||
|
||
// UpdateManifest looks for the manifest for the identified resource, | ||
// reads its contents, applies f(contents), and writes the results | ||
// back to the file. | ||
func UpdateManifest(m Manifests, root string, paths []string, id flux.ResourceID, f func(manifest []byte) ([]byte, error)) error { | ||
resources, err := m.LoadManifests(root, paths) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resource, ok := resources[id.String()] | ||
if !ok { | ||
return ErrResourceNotFound(id.String()) | ||
} | ||
|
||
path := filepath.Join(root, resource.Source()) | ||
def, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
newDef, err := f(def) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fi, err := os.Stat(path) | ||
if err != nil { | ||
return err | ||
} | ||
return ioutil.WriteFile(path, newDef, fi.Mode()) | ||
LoadManifests(baseDir string, paths []string) ([]resource.Resource, error) | ||
// ParseManifest parses the content of a manifest and its source location into resources | ||
ParseManifest(def []byte, source string) ([]resource.Resource, error) | ||
// Set the image of a container in a manifest's bytes to that given | ||
SetWorkloadContainerImage(def []byte, resourceID flux.ResourceID, container string, newImageID image.Ref) ([]byte, error) | ||
// UpdatWorkloadPolicies modifies a manifest to apply the policy update specified | ||
UpdateWorkloadPolicies(def []byte, id flux.ResourceID, update policy.Update) ([]byte, error) | ||
// TODO(fons): the following function (in conjunction with the one above) is horrible, maybe move | ||
// GetAnnotationChangesForPolicyUpdate to its own interface and pass that to UpdateWorkloadPolicies? | ||
// GetAnnotationChangesForPolicyUpdate translates a policy update into annotation updates | ||
GetAnnotationChangesForPolicyUpdate(workload resource.Workload, update policy.Update) ([]AnnotationChange, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.