Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Move ResourceID from root to resource package #2201

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/v11/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package v11
import (
"context"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/api/v10"
"github.com/weaveworks/flux/api/v6"
"github.com/weaveworks/flux/resource"
)

type ListServicesOptions struct {
Namespace string
Services []flux.ResourceID
Services []resource.ID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is SO much nicer, it is like a breath of fresh air!

}

type Server interface {
Expand Down
8 changes: 4 additions & 4 deletions api/v6/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package v6
import (
"context"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/cluster"
"github.com/weaveworks/flux/git"
"github.com/weaveworks/flux/job"
"github.com/weaveworks/flux/resource"
"github.com/weaveworks/flux/ssh"
"github.com/weaveworks/flux/update"
)

type ImageStatus struct {
ID flux.ResourceID
ID resource.ID
Containers []Container
}

Expand All @@ -31,13 +31,13 @@ const (
)

type ControllerStatus struct {
ID flux.ResourceID
ID resource.ID
Containers []Container
ReadOnly ReadOnlyReason
Status string
Rollout cluster.RolloutStatus
SyncError string
Antecedent flux.ResourceID
Antecedent resource.ID
Labels map[string]string
Automated bool
Locked bool
Expand Down
9 changes: 4 additions & 5 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/resource"
"github.com/weaveworks/flux/ssh"
Expand All @@ -27,8 +26,8 @@ const (
type Cluster interface {
// Get all of the services (optionally, from a specific namespace), excluding those
AllWorkloads(ctx context.Context, maybeNamespace string) ([]Workload, error)
SomeWorkloads(ctx context.Context, ids []flux.ResourceID) ([]Workload, error)
IsAllowedResource(flux.ResourceID) bool
SomeWorkloads(ctx context.Context, ids []resource.ID) ([]Workload, error)
IsAllowedResource(resource.ID) bool
Ping() error
Export(ctx context.Context) ([]byte, error)
Sync(SyncSet) error
Expand Down Expand Up @@ -60,7 +59,7 @@ type RolloutStatus struct {

// Workload describes a cluster resource that declares versioned images.
type Workload struct {
ID flux.ResourceID
ID resource.ID
Status string // A status summary for display
// Is the controller considered read-only because it's under the
// control of the platform. In the case of Kubernetes, we simply
Expand All @@ -70,7 +69,7 @@ type Workload struct {
// resource through some mechanism (like an operator, or custom
// resource controller), we try to record the ID of that resource
// in this field.
Antecedent flux.ResourceID
Antecedent resource.ID
Labels map[string]string
Policies policy.Set
Rollout RolloutStatus
Expand Down
4 changes: 2 additions & 2 deletions cluster/kubernetes/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/registry"
"github.com/weaveworks/flux/resource"
)

func mergeCredentials(log func(...interface{}) error,
Expand Down Expand Up @@ -145,7 +145,7 @@ func (c *Cluster) ImagesToFetch() registry.ImageCreds {

imageCreds := make(registry.ImageCreds)
for _, workload := range workloads {
logger := log.With(c.logger, "resource", flux.MakeResourceID(ns.Name, kind, workload.GetName()))
logger := log.With(c.logger, "resource", resource.MakeID(ns.Name, kind, workload.GetName()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAAASSS

mergeCredentials(logger.Log, c.includeImage, c.client, ns.Name, workload.podTemplate, imageCreds, seenCreds)
}

Expand Down
16 changes: 8 additions & 8 deletions cluster/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
k8sclientdynamic "k8s.io/client-go/dynamic"
k8sclient "k8s.io/client-go/kubernetes"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/cluster"
"github.com/weaveworks/flux/cluster/kubernetes/resource"
kresource "github.com/weaveworks/flux/cluster/kubernetes/resource"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to have consistency here, nice

fhrclient "github.com/weaveworks/flux/integrations/client/clientset/versioned"
"github.com/weaveworks/flux/ssh"
"github.com/weaveworks/flux/resource"
)

type coreClient k8sclient.Interface
Expand Down Expand Up @@ -98,7 +98,7 @@ type Cluster struct {

// syncErrors keeps a record of all per-resource errors during
// the sync from Git repo to the cluster.
syncErrors map[flux.ResourceID]error
syncErrors map[resource.ID]error
muSyncErrors sync.RWMutex

allowedNamespaces []string
Expand Down Expand Up @@ -128,7 +128,7 @@ func NewCluster(client ExtendedClient, applier Applier, sshKeyRing ssh.KeyRing,
// SomeWorkloads returns the workloads named, missing out any that don't
// exist in the cluster or aren't in an allowed namespace.
// They do not necessarily have to be returned in the order requested.
func (c *Cluster) SomeWorkloads(ctx context.Context, ids []flux.ResourceID) (res []cluster.Workload, err error) {
func (c *Cluster) SomeWorkloads(ctx context.Context, ids []resource.ID) (res []cluster.Workload, err error) {
var workloads []cluster.Workload
for _, id := range ids {
if !c.IsAllowedResource(id) {
Expand Down Expand Up @@ -192,7 +192,7 @@ func (c *Cluster) AllWorkloads(ctx context.Context, namespace string) (res []clu

for _, workload := range workloads {
if !isAddon(workload) {
id := flux.MakeResourceID(ns.Name, kind, workload.GetName())
id := resource.MakeID(ns.Name, kind, workload.GetName())
c.muSyncErrors.RLock()
workload.syncError = c.syncErrors[id]
c.muSyncErrors.RUnlock()
Expand All @@ -208,7 +208,7 @@ func (c *Cluster) AllWorkloads(ctx context.Context, namespace string) (res []clu
func (c *Cluster) setSyncErrors(errs cluster.SyncError) {
c.muSyncErrors.Lock()
defer c.muSyncErrors.Unlock()
c.syncErrors = make(map[flux.ResourceID]error)
c.syncErrors = make(map[resource.ID]error)
for _, e := range errs {
c.syncErrors[e.ResourceID] = e.Error
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func (c *Cluster) getAllowedAndExistingNamespaces(ctx context.Context) ([]apiv1.
return namespaces.Items, nil
}

func (c *Cluster) IsAllowedResource(id flux.ResourceID) bool {
func (c *Cluster) IsAllowedResource(id resource.ID) bool {
if len(c.allowedNamespaces) == 0 {
// All resources are allowed when all namespaces are allowed
return true
Expand All @@ -326,7 +326,7 @@ func (c *Cluster) IsAllowedResource(id flux.ResourceID) bool {
namespace, kind, name := id.Components()
namespaceToCheck := namespace

if namespace == resource.ClusterScope {
if namespace == kresource.ClusterScope {
// All cluster-scoped resources (not namespaced) are allowed ...
if kind != "namespace" {
return true
Expand Down
3 changes: 1 addition & 2 deletions cluster/kubernetes/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/weaveworks/flux"
kresource "github.com/weaveworks/flux/cluster/kubernetes/resource"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/resource"
Expand Down Expand Up @@ -133,7 +132,7 @@ func (m *manifests) ParseManifest(def []byte, source string) (map[string]resourc
return result, nil
}

func (m *manifests) SetWorkloadContainerImage(def []byte, id flux.ResourceID, container string, image image.Ref) ([]byte, error) {
func (m *manifests) SetWorkloadContainerImage(def []byte, id resource.ID, container string, image image.Ref) ([]byte, error) {
return updateWorkload(def, id, container, image)
}

Expand Down
22 changes: 11 additions & 11 deletions cluster/kubernetes/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch"
k8sscheme "k8s.io/client-go/kubernetes/scheme"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/cluster/kubernetes/resource"
kresource "github.com/weaveworks/flux/cluster/kubernetes/resource"
"github.com/weaveworks/flux/resource"
)

func createManifestPatch(originalManifests, modifiedManifests []byte, originalSource, modifiedSource string) ([]byte, error) {
originalResources, err := resource.ParseMultidoc(originalManifests, originalSource)
originalResources, err := kresource.ParseMultidoc(originalManifests, originalSource)
if err != nil {
fmt.Errorf("cannot parse %s: %s", originalSource, err)
}

modifiedResources, err := resource.ParseMultidoc(modifiedManifests, modifiedSource)
modifiedResources, err := kresource.ParseMultidoc(modifiedManifests, modifiedSource)
if err != nil {
fmt.Errorf("cannot parse %s: %s", modifiedSource, err)
}
Expand Down Expand Up @@ -61,12 +61,12 @@ func createManifestPatch(originalManifests, modifiedManifests []byte, originalSo
}

func applyManifestPatch(originalManifests, patchManifests []byte, originalSource, patchSource string) ([]byte, error) {
originalResources, err := resource.ParseMultidoc(originalManifests, originalSource)
originalResources, err := kresource.ParseMultidoc(originalManifests, originalSource)
if err != nil {
return nil, fmt.Errorf("cannot parse %s: %s", originalSource, err)
}

patchResources, err := resource.ParseMultidoc(patchManifests, patchSource)
patchResources, err := kresource.ParseMultidoc(patchManifests, patchSource)
if err != nil {
return nil, fmt.Errorf("cannot parse %s: %s", patchSource, err)
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func getFullScheme() *runtime.Scheme {
return fullScheme
}

func getPatch(originalManifest resource.KubeManifest, modifiedManifest resource.KubeManifest, scheme *runtime.Scheme) ([]byte, error) {
func getPatch(originalManifest kresource.KubeManifest, modifiedManifest kresource.KubeManifest, scheme *runtime.Scheme) ([]byte, error) {
groupVersion, err := schema.ParseGroupVersion(originalManifest.GroupVersion())
if err != nil {
return nil, fmt.Errorf("cannot parse groupVersion %q: %s", originalManifest.GroupVersion(), err)
Expand Down Expand Up @@ -192,7 +192,7 @@ func addIdentifyingData(apiVersion string, kind string, name string, namespace s
return obj, err
}

func applyPatch(originalManifest, patchManifest resource.KubeManifest, scheme *runtime.Scheme) ([]byte, error) {
func applyPatch(originalManifest, patchManifest kresource.KubeManifest, scheme *runtime.Scheme) ([]byte, error) {
groupVersion, err := schema.ParseGroupVersion(originalManifest.GroupVersion())
if err != nil {
return nil, fmt.Errorf("cannot parse groupVersion %q: %s", originalManifest.GroupVersion(), err)
Expand Down Expand Up @@ -227,8 +227,8 @@ func applyPatch(originalManifest, patchManifest resource.KubeManifest, scheme *r
return patched, nil
}

// resourceID works like Resource.ResourceID() but avoids <cluster> namespaces,
// resourceID works like Resource.ID() but avoids <cluster> namespaces,
// since they may be incorrect
func resourceID(manifest resource.KubeManifest) flux.ResourceID {
return flux.MakeResourceID(manifest.GetNamespace(), manifest.GetKind(), manifest.GetKind())
func resourceID(manifest kresource.KubeManifest) resource.ID {
return resource.MakeID(manifest.GetNamespace(), manifest.GetKind(), manifest.GetKind())
}
4 changes: 1 addition & 3 deletions cluster/kubernetes/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import (

"github.com/pkg/errors"

"github.com/weaveworks/flux"
kresource "github.com/weaveworks/flux/cluster/kubernetes/resource"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/resource"
)

func (m *manifests) UpdateWorkloadPolicies(def []byte, id flux.ResourceID, update policy.Update) ([]byte, error) {
func (m *manifests) UpdateWorkloadPolicies(def []byte, id resource.ID, update resource.PolicyUpdate) ([]byte, error) {
resources, err := m.ParseManifest(def, "stdin")
if err != nil {
return nil, err
Expand Down
Loading