Skip to content

Commit

Permalink
Merge pull request #53 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Add cross namespace bundles and git targets
  • Loading branch information
ibuildthecloud authored Aug 26, 2020
2 parents bdb9b8e + 6d3f85a commit 6e25257
Show file tree
Hide file tree
Showing 19 changed files with 823 additions and 60 deletions.
2 changes: 1 addition & 1 deletion charts/fleet-crd/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ appVersion: 0.0.0
icon: https://charts.rancher.io/assets/logos/fleet.svg
annotations:
catalog.cattle.io/certified: rancher
catalog.cattle.io/hidden: "false"
catalog.cattle.io/hidden: "true"
catalog.cattle.io/namespace: fleet-system
catalog.cattle.io/provides-gvr: clusters.fleet.cattle.io/v1alpha1
catalog.cattle.io/release-name: fleet-crd
16 changes: 13 additions & 3 deletions charts/fleet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ agentImage:
# Example: https://example.com:6443
apiServerURL: ""

# For cluster auto registration the pem encoded value of the CA of the Kubernetes API server must be set here
# For cluster registration the pem encoded value of the CA of the Kubernetes API server must be set here
# If left empty it is assumed this Kubernetes API TLS is signed by a well known CA.
apiServerCA: ""

githubURLPrefix: https://github.com
# The URL of the webhook reciever that will receive webhooks events from GitHub
# Refer to documentation on how to setup Ingress or a Service LoadBalancer.
webhookReceiverURL: ""

# All repo URLs that match the below prefixes will be assumed to be github and a
# webhook will be setup if webhookReceiverURL is also set
githubURLPrefix: https://github.com

bootstrap:
# The namespace that will be autocreated and the local cluster will be registered in
namespace: fleet-local
# A repo to add at install time that will deploy to the local cluster. This allows
# one to fully bootstrap fleet, it's configuration and all it's downstream clusters
# in one shot.
repo: ""
secret: ""
branch: master
dirs: ""
namespace: fleet-local
1 change: 0 additions & 1 deletion docs/arch.drawio

This file was deleted.

Binary file modified docs/arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 35 additions & 3 deletions modules/cli/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"path/filepath"
"regexp"

"github.com/sirupsen/logrus"

"github.com/rancher/fleet/modules/cli/pkg/client"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/bundle"
"github.com/rancher/wrangler/pkg/yaml"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -27,6 +27,7 @@ var (

type Options struct {
BundleFile string
TargetsFile string
Compress bool
BundleReader io.Reader
Output io.Writer
Expand Down Expand Up @@ -81,9 +82,40 @@ func readBundle(ctx context.Context, baseDir string, opts *Options) (*bundle.Bun
return bundle.New(&bundleResource)
}

return bundle.Open(ctx, baseDir, opts.BundleFile, &bundle.Options{
b, err := bundle.Open(ctx, baseDir, opts.BundleFile, &bundle.Options{
Compress: opts.Compress,
})
if err != nil {
return nil, err
}

return appendTargets(b, opts.TargetsFile)
}

func appendTargets(b *bundle.Bundle, targetsFile string) (*bundle.Bundle, error) {
if targetsFile == "" {
return b, nil
}

def := b.Definition.DeepCopy()
data, err := ioutil.ReadFile(targetsFile)
if err != nil {
return nil, err
}

spec := &fleet.BundleSpec{}
if err := yaml.Unmarshal(data, spec); err != nil {
return nil, err
}

for _, target := range spec.Targets {
def.Spec.Targets = append(def.Spec.Targets, target)
}
for _, targetRestriction := range spec.TargetRestrictions {
def.Spec.TargetRestrictions = append(def.Spec.TargetRestrictions, targetRestriction)
}

return bundle.New(def)
}

func createName(name, baseDir string) string {
Expand Down
1 change: 1 addition & 0 deletions modules/cli/cmds/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Apply struct {
OutputArgsNoDefault
Label map[string]string `usage:"Labels to apply to created bundles" short:"l"`
File string `usage:"Read full bundle contents from file" short:"f"`
TargetsFile string `usage:"Addition source of targets and restrictions to be append"`
Compress bool `usage:"Force all resources to be compress" short:"c"`
ServiceAccount string `usage:"Service account to assign to bundle created" short:"a"`
}
Expand Down
29 changes: 24 additions & 5 deletions pkg/apis/fleet.cattle.io/v1alpha1/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,26 @@ type Bundle struct {
Status BundleStatus `json:"status"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type BundleNamespaceMapping struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

BundleSelector *metav1.LabelSelector `json:"bundleSelector,omitempty"`
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
}

type BundleSpec struct {
BundleDeploymentOptions

Paused bool `json:"paused,omitempty"`
RolloutStrategy *RolloutStrategy `json:"rolloutStrategy,omitempty"`
Resources []BundleResource `json:"resources,omitempty"`
Overlays []BundleOverlay `json:"overlays,omitempty"`
Targets []BundleTarget `json:"targets,omitempty"`
Paused bool `json:"paused,omitempty"`
RolloutStrategy *RolloutStrategy `json:"rolloutStrategy,omitempty"`
Resources []BundleResource `json:"resources,omitempty"`
Overlays []BundleOverlay `json:"overlays,omitempty"`
Targets []BundleTarget `json:"targets,omitempty"`
TargetRestrictions []BundleTargetRestriction `json:"targetRestrictions,omitempty"`
}

type BundleResource struct {
Expand Down Expand Up @@ -73,6 +85,13 @@ type BundleOverlay struct {
Resources []BundleResource `json:"resources,omitempty"`
}

type BundleTargetRestriction struct {
Name string `json:"name,omitempty"`
ClusterSelector *metav1.LabelSelector `json:"clusterSelector,omitempty"`
ClusterGroup string `json:"clusterGroup,omitempty"`
ClusterGroupSelector *metav1.LabelSelector `json:"clusterGroupSelector,omitempty"`
}

type BundleTarget struct {
BundleDeploymentOptions
Name string `json:"name,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ type GitRepoSpec struct {

// ServiceAccount used in the downstream cluster for deployment
ServiceAccount string `json:"serviceAccount,omitempty"`

// Targets is a list of target this repo will deploy to
Targets []GitTarget `json:"targets,omitempty"`
}

type GitTarget struct {
Name string `json:"name,omitempty"`
ClusterSelector *metav1.LabelSelector `json:"clusterSelector,omitempty"`
ClusterGroup string `json:"clusterGroup,omitempty"`
ClusterGroupSelector *metav1.LabelSelector `json:"clusterGroupSelector,omitempty"`
}

type GitRepoStatus struct {
Expand Down
135 changes: 135 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/zz_generated_deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/zz_generated_list_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/zz_generated_register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6e25257

Please sign in to comment.