Skip to content
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
7 changes: 5 additions & 2 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ helm_remote('tf-controller',
repo_url='https://weaveworks.github.io/tf-controller',
namespace='flux-system')

# Note for MacOS users:
# for this to work you need to run:
# brew install FiloSottile/musl-cross/musl-cross
# https://github.com/mattn/go-sqlite3#cross-compiling-from-mac-osx
native_build = os.getenv('NATIVE_BUILD', False)
skip_ui = os.getenv("SKIP_UI_BUILD", False)

if native_build:
local_resource(
'clusters-service',
'GOOS=linux GOARCH=amd64 make build',
'make build-linux',
deps=[
'./cmd/clusters-service',
'./pkg'
Expand Down
19 changes: 17 additions & 2 deletions cmd/clusters-service/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
CONTROLLER_TOOLS_VERSION ?= v0.9.2
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
GOOS := $(shell go env GOOS)
ifeq ($(GOOS),linux)
cgo_ldflags=-linkmode external -w -extldflags "-static"
else
# darwin doesn't like -static
cgo_ldflags=-linkmode external -w
endif


## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
Expand All @@ -21,9 +29,16 @@ install:

.PHONY: build
build:
# Alpine needs these extra CGO and -a flags to "see" the binary
CGO_ENABLED=0 go build -a -installsuffix cgo -o bin/clusters-service main.go
CGO_ENABLED=1 go build -ldflags "$(cgo_ldflags)" -a -installsuffix cgo -o bin/clusters-service main.go

.PHONY: build-linux
build-linux:
# set CC and CXX cross compile vars for darwin
ifeq ($(shell uname),Darwin)
CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ GOARCH=amd64 GOOS=linux CGO_ENABLED=1 go build -ldflags "-linkmode external -extldflags -static" -a -installsuffix cgo -o bin/clusters-service main.go
else
GOARCH=amd64 GOOS=linux CGO_ENABLED=1 go build -ldflags "-linkmode external -extldflags -static" -a -installsuffix cgo -o bin/clusters-service main.go
endif

.PHONY: crd-manifests
crd-manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
Expand Down
1 change: 1 addition & 0 deletions cmd/clusters-service/api/cluster_services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ message RepositoryChart {
string name = 1;
// This is the available versions in reverse semver order.
repeated string versions = 2;
string layer = 3;
}

message ListChartsForRepositoryResponse {
Expand Down
5 changes: 4 additions & 1 deletion cmd/clusters-service/api/cluster_services.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@
}
},
"additionalProperties": {},
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := anypb.New(foo)\n if err != nil {\n ...\n }\n ...\n foo := \u0026pb.Foo{}\n if err := any.UnmarshalTo(foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\nExample 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\nExample 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := anypb.New(foo)\n if err != nil {\n ...\n }\n ...\n foo := \u0026pb.Foo{}\n if err := any.UnmarshalTo(foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
},
"rpcStatus": {
"type": "object",
Expand Down Expand Up @@ -2112,6 +2112,9 @@
"type": "string"
},
"description": "This is the available versions in reverse semver order."
},
"layer": {
"type": "string"
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions cmd/clusters-service/api/profiles/profiles.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"parameters": [
{
"name": "helmRepoName",
"description": "The name of the HelmRepository.",
"description": "The name of the HelmRepository",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "helmRepoNamespace",
"description": "The namespace of the HelmRepository.",
"description": "The namespace of the HelmRepository",
"in": "query",
"required": false,
"type": "string"
Expand Down Expand Up @@ -91,14 +91,14 @@
},
{
"name": "helmRepoName",
"description": "The name of the HelmRepository.",
"description": "The name of the HelmRepository",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "helmRepoNamespace",
"description": "The namespace of the HelmRepository.",
"description": "The namespace of the HelmRepository",
"in": "query",
"required": false,
"type": "string"
Expand Down Expand Up @@ -142,7 +142,7 @@
}
},
"additionalProperties": {},
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := anypb.New(foo)\n if err != nil {\n ...\n }\n ...\n foo := \u0026pb.Foo{}\n if err := any.UnmarshalTo(foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\nExample 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\nExample 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := anypb.New(foo)\n if err != nil {\n ...\n }\n ...\n foo := \u0026pb.Foo{}\n if err := any.UnmarshalTo(foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
},
"rpcStatus": {
"type": "object",
Expand Down
9 changes: 9 additions & 0 deletions cmd/clusters-service/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/weaveworks/weave-gitops-enterprise/cmd/clusters-service/pkg/git"
"github.com/weaveworks/weave-gitops-enterprise/cmd/clusters-service/pkg/mgmtfetcher"
"github.com/weaveworks/weave-gitops-enterprise/cmd/clusters-service/pkg/server"
"github.com/weaveworks/weave-gitops-enterprise/pkg/helm"
"github.com/weaveworks/weave-gitops/core/clustersmngr"
core "github.com/weaveworks/weave-gitops/core/server"
"github.com/weaveworks/weave-gitops/pkg/kube"
Expand Down Expand Up @@ -44,6 +45,7 @@ type Options struct {
NoTLS bool
DevMode bool
ClustersManager clustersmngr.ClustersManager
ChartsCache *helm.HelmChartIndexer
KubernetesClientSet kubernetes.Interface
ManagementFetcher *mgmtfetcher.ManagementCrossNamespacesFetcher
}
Expand Down Expand Up @@ -218,6 +220,13 @@ func WithClustersManager(factory clustersmngr.ClustersManager) Option {
}
}

// WithClustersCache defines the clusters cache that will be use for cross-cluster queries.
func WithChartsCache(chartCache *helm.HelmChartIndexer) Option {
return func(o *Options) {
o.ChartsCache = chartCache
}
}

// WithKubernetesClientSet defines the kuberntes client set that will be used for
func WithKubernetesClientSet(kubernetesClientSet kubernetes.Interface) Option {
return func(o *Options) {
Expand Down
36 changes: 35 additions & 1 deletion cmd/clusters-service/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
tfctrl "github.com/weaveworks/tf-controller/api/v1alpha1"
ent "github.com/weaveworks/weave-gitops-enterprise-credentials/pkg/entitlement"
"github.com/weaveworks/weave-gitops-enterprise/pkg/cluster/namespaces"
"github.com/weaveworks/weave-gitops-enterprise/pkg/helm"
"github.com/weaveworks/weave-gitops-enterprise/pkg/helm/multiwatcher"
"github.com/weaveworks/weave-gitops-enterprise/pkg/helm/watcher"
"github.com/weaveworks/weave-gitops-enterprise/pkg/helm/watcher/cache"
"github.com/weaveworks/weave-gitops/cmd/gitops/cmderrors"
Expand All @@ -54,11 +56,13 @@ import (
authv1 "k8s.io/api/authentication/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
runtimeUtil "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/discovery"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"

Expand Down Expand Up @@ -336,8 +340,33 @@ func StartServer(ctx context.Context, log logr.Logger, tempDir string, p Params)
return fmt.Errorf("failed to start the watcher: %w", err)
}

controllerContext := ctrl.SetupSignalHandler()

go func() {
if err := profileWatcher.StartWatcher(controllerContext, log); err != nil {
log.Error(err, "failed to start profile watcher")
os.Exit(1)
}
}()

chartsCache, err := helm.NewChartIndexer(p.ProfileCacheLocation)
if err != nil {
return fmt.Errorf("could not create charts cache: %w", err)
}

multiWatcher, err := multiwatcher.NewWatcher(multiwatcher.Options{
ClientConfig: kubeClientConfig,
ClusterRef: types.NamespacedName{Name: "management"},
Cache: chartsCache,
ValuesFetcher: helm.NewValuesFetcher(),
KubeClient: kubeClient,
})
if err != nil {
return fmt.Errorf("failed to start the multiwatcher: %w", err)
}

go func() {
if err := profileWatcher.StartWatcher(log); err != nil {
if err := multiWatcher.StartWatcher(controllerContext, log); err != nil {
log.Error(err, "failed to start profile watcher")
os.Exit(1)
}
Expand Down Expand Up @@ -441,6 +470,7 @@ func StartServer(ctx context.Context, log logr.Logger, tempDir string, p Params)
WithRuntimeNamespace(p.RuntimeNamespace),
WithDevMode(p.DevMode),
WithClustersManager(clustersManager),
WithChartsCache(chartsCache),
WithKubernetesClientSet(kubernetesClientSet),
)
}
Expand Down Expand Up @@ -498,6 +528,10 @@ func RunInProcessGateway(ctx context.Context, addr string, setters ...Option) er
ProfileHelmRepositoryName: args.ProfileHelmRepository,
HelmRepositoryCacheDir: args.HelmRepositoryCacheDirectory,
CAPIEnabled: args.CAPIEnabled,
ChartJobs: helm.NewJobs(),
ChartsCache: args.ChartsCache,
ValuesFetcher: helm.NewValuesFetcher(),
RestConfig: args.CoreServerConfig.RestCfg,
ManagementFetcher: args.ManagementFetcher,
},
)
Expand Down
7 changes: 3 additions & 4 deletions cmd/clusters-service/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"os"
Expand Down Expand Up @@ -35,7 +35,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/discovery"
fakeclientset "k8s.io/client-go/kubernetes/fake"
k8sFake "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -116,7 +115,7 @@ func TestPipelinesServer(t *testing.T) {
res, err := client.Get(fmt.Sprintf("https://localhost:%s/v1/pipelines", port))
assert.NoError(t, err)

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
assert.NoError(t, err)

assert.Equal(t, res.StatusCode, http.StatusOK, string(body))
Expand Down Expand Up @@ -180,7 +179,7 @@ func runServer(t *testing.T, ctx context.Context, k client.Client, ns string, ad
go func(ctx context.Context) {
coreConfig := fakeCoreConfig(t, log)
appsConfig := fakeAppsConfig(k, log)
clientSet := k8sFake.NewSimpleClientset(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "flux-system"}})
clientSet := fakeclientset.NewSimpleClientset(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "flux-system"}})
mgmtFetcher := mgmtfetcher.NewManagementCrossNamespacesFetcher(&mgmtfetcherfake.FakeNamespaceCache{
Namespaces: []*corev1.Namespace{
{
Expand Down
Loading