Skip to content

Commit

Permalink
Merge pull request #14 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Print resource on flt apply create
  • Loading branch information
ibuildthecloud authored Mar 31, 2020
2 parents 9a80521 + a391bc8 commit 8b734af
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Rancher Fleet
Fleet
=============

### Status: ALPHA (actively looking for feedback)
Expand All @@ -24,7 +24,7 @@ clustergroup.fleet.cattle.io/bobby 2 [cluster-93d18642-217a

## Introduction

Rancher Fleet is a Kubernetes cluster fleet manager specifically designed to address the challenges of running
Fleet is a Kubernetes cluster fleet manager specifically designed to address the challenges of running
thousands to millions of clusters across the world. While it's designed for massive scale the concepts still
apply for even small deployments of less than 10 clusters. Fleet is lightweight enough to run on the smallest of
deployments too and even has merit in a single node cluster managing only itself. The primary use case of Fleet is
Expand Down
2 changes: 1 addition & 1 deletion docs/arch.drawio

Large diffs are not rendered by default.

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.
17 changes: 17 additions & 0 deletions modules/cli/agentmanifest/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"io/ioutil"
"net/url"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -100,6 +102,17 @@ func getClusterGroup(ctx context.Context, clusterGroupName string, client *clien
}
}

func checkHost(host string) error {
u, err := url.Parse(host)
if err != nil {
return errors.Wrapf(err, "invalid host, override with --server-url")
}
if u.Hostname() == "localhost" || strings.HasPrefix(u.Hostname(), "127.") {
return fmt.Errorf("invalid host %s, use --server-url to set a proper server URL", u.Hostname())
}
return nil
}

func getKubeConfig(kubeConfig string, namespace, token, host string, ca []byte, noCA bool) (string, error) {
cc := kubeconfig.GetNonInteractiveClientConfig(kubeConfig)
cfg, err := cc.RawConfig()
Expand All @@ -112,6 +125,10 @@ func getKubeConfig(kubeConfig string, namespace, token, host string, ca []byte,
return "", err
}

if err := checkHost(host); err != nil {
return "", err
}

if noCA {
ca = nil
} else {
Expand Down
2 changes: 1 addition & 1 deletion modules/cli/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func save(client *client.Getter, bundle *fleet.Bundle) error {
if apierrors.IsNotFound(err) {
_, err = c.Fleet.Bundle().Create(bundle)
if err == nil {
fmt.Printf("%s/%s\n", obj.Namespace, obj.Name)
fmt.Printf("%s/%s\n", bundle.Namespace, bundle.Name)
}
return err
} else if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/cluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (h *handler) OnClusterChanged(cluster *fleet.Cluster, status fleet.ClusterS

for _, app := range bundleDeployments {
state := summary.GetDeploymentState(app)
summary.IncrementState(&status.Summary, app.Name, state, summary.ReadyMessageFromCondition(app.Status.Conditions))
summary.IncrementState(&status.Summary, app.Name, state, summary.MessageFromDeployment(app))
status.Summary.DesiredReady++
}

Expand Down
17 changes: 14 additions & 3 deletions pkg/helmdeployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"time"

"helm.sh/helm/v3/pkg/kube"

"github.com/rancher/fleet/modules/agent/pkg/deployer"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/kustomize"
Expand All @@ -27,11 +29,14 @@ import (

type helm struct {
cfg action.Configuration
getter genericclioptions.RESTClientGetter
template bool
}

func NewHelm(namespace string, getter genericclioptions.RESTClientGetter) (deployer.Deployer, error) {
h := &helm{}
h := &helm{
getter: getter,
}
if err := h.cfg.Init(getter, namespace, "secrets", logrus.Infof); err != nil {
return nil, err
}
Expand Down Expand Up @@ -174,13 +179,19 @@ func (h *helm) install(bundleID string, manifest *manifest.Manifest, chart *char
}
}

// override global namespace default
kc := kube.New(h.getter)
kc.Namespace = namespace
cfg := h.cfg
cfg.KubeClient = kc

install, err := h.mustInstall(bundleID)
if err != nil {
return nil, err
}

if install {
u := action.NewInstall(&h.cfg)
u := action.NewInstall(&cfg)
u.ClientOnly = h.template
u.Adopt = true
u.Replace = true
Expand All @@ -198,7 +209,7 @@ func (h *helm) install(bundleID string, manifest *manifest.Manifest, chart *char
return u.Run(chart, vals)
}

u := action.NewUpgrade(&h.cfg)
u := action.NewUpgrade(&cfg)
u.Adopt = true
u.Namespace = namespace
u.Timeout = timeout
Expand Down
15 changes: 13 additions & 2 deletions pkg/summary/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,26 @@ func SetReadyConditions(obj interface{}, summary fleet.BundleSummary) {
c.Message(obj, msg)
}

func ReadyMessageFromCondition(conds []genericcondition.GenericCondition) string {
func MessageFromCondition(conditionType string, conds []genericcondition.GenericCondition) string {
for _, cond := range conds {
if cond.Type == "Ready" {
if cond.Type == conditionType {
return cond.Message
}
}
return ""
}

func MessageFromDeployment(deployment *fleet.BundleDeployment) string {
if deployment == nil {
return ""
}
message := MessageFromCondition("Deployed", deployment.Status.Conditions)
if message == "" {
message = MessageFromCondition("Monitored", deployment.Status.Conditions)
}
return message
}

func ReadyMessage(summary fleet.BundleSummary) string {
var messages []string
for msg, count := range map[fleet.BundleState]int{
Expand Down
5 changes: 1 addition & 4 deletions pkg/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,5 @@ func (t *Target) State() fleet.BundleState {
}

func (t *Target) Message() string {
if t.Deployment == nil {
return ""
}
return summary.ReadyMessageFromCondition(t.Deployment.Status.Conditions)
return summary.MessageFromDeployment(t.Deployment)
}

0 comments on commit 8b734af

Please sign in to comment.