Skip to content

Commit

Permalink
Merge pull request #321 from gianlucam76/release-0.15
Browse files Browse the repository at this point in the history
Release 0.15.3
  • Loading branch information
gianlucam76 committed Sep 8, 2023
2 parents f8f9252 + f15a0ec commit d52b44d
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'main'
- 'dev'
pull_request:
types: [opened, edited, reopened]
types: [opened, edited, synchronize, reopened]


jobs:
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.20.0
- name: Build
run: make build
- name: FMT
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.20.0
- name: ut
run: make test
env:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ARCH ?= amd64
OS ?= $(shell uname -s | tr A-Z a-z)
K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= v0.15.2
TAG ?= v0.15.3

# Get cluster-api version and build ldflags
clusterapi := $(shell go list -m sigs.k8s.io/cluster-api)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ where GitRepository synced with Flux contains following resources:

Refer to [examples](./examples/) for more complex examples.

## Give projectsveltos a try

If you want to try projectsveltos with a test cluster:

1. git clone https://github.com/projectsveltos/addon-controller
2. make quickstart

will create a management cluster using Kind, deploy clusterAPI and projectsveltos, create a workload cluster powered by clusterAPI.

## Sveltos in action

![Sveltos in action](doc/SveltosOverview.gif)
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: projectsveltos/addon-controller-amd64:v0.15.2
- image: projectsveltos/addon-controller-amd64:v0.15.3
name: controller
14 changes: 14 additions & 0 deletions controllers/clustersummary_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func ConfigMapPredicates(logger logr.Logger) predicate.Funcs {
return true
}

if !reflect.DeepEqual(oldConfigMap.Annotations, newConfigMap.Annotations) {
log.V(logs.LogVerbose).Info(
"ConfigMap Annotation changed. Will attempt to reconcile associated ClusterSummaries.",
)
return true
}

if !reflect.DeepEqual(oldConfigMap.BinaryData, newConfigMap.BinaryData) {
log.V(logs.LogVerbose).Info(
"ConfigMap BinaryData changed. Will attempt to reconcile associated ClusterSummaries.",
Expand Down Expand Up @@ -100,6 +107,13 @@ func SecretPredicates(logger logr.Logger) predicate.Funcs {
return true
}

if !reflect.DeepEqual(oldSecret.Annotations, newSecret.Annotations) {
log.V(logs.LogVerbose).Info(
"Secret Annotation changed. Will attempt to reconcile associated ClusterSummaries.",
)
return true
}

// otherwise, return false
log.V(logs.LogVerbose).Info(
"Secret did not match expected conditions. Will not attempt to reconcile associated ClusterSummaries.")
Expand Down
42 changes: 42 additions & 0 deletions controllers/clustersummary_predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ var _ = Describe("Clustersummary Predicates: ConfigMapPredicates", func() {
result := configMapPredicate.Update(e)
Expect(result).To(BeFalse())
})

It("Update returns true when annotations changed", func() {
configMapPredicate := controllers.ConfigMapPredicates(logger)
configMap.Annotations = map[string]string{
"projectsveltos.io/template": "true",
}

oldConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: configMap.Name,
},
}

e := event.UpdateEvent{
ObjectNew: configMap,
ObjectOld: oldConfigMap,
}

result := configMapPredicate.Update(e)
Expect(result).To(BeTrue())
})
})

var _ = Describe("Clustersummary Predicates: SecretPredicates", func() {
Expand Down Expand Up @@ -222,6 +243,27 @@ var _ = Describe("Clustersummary Predicates: SecretPredicates", func() {
result := secretPredicate.Update(e)
Expect(result).To(BeFalse())
})

It("Update returns true when annotations changed", func() {
secretPredicate := controllers.SecretPredicates(logger)
secret.Annotations = map[string]string{
"projectsveltos.io/template": "true",
}

oldSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secret.Name,
},
}

e := event.UpdateEvent{
ObjectNew: secret,
ObjectOld: oldSecret,
}

result := secretPredicate.Update(e)
Expect(result).To(BeTrue())
})
})

var _ = Describe("ClusterProfile Predicates: FluxSourcePredicates", func() {
Expand Down
4 changes: 4 additions & 0 deletions controllers/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@ var (
ConvertResourceReportsToObjectReference = convertResourceReportsToObjectReference
ConvertHelmResourcesToObjectReference = convertHelmResourcesToObjectReference
)

var (
GetMgmtResourceName = getMgmtResourceName
)
37 changes: 35 additions & 2 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ limitations under the License.
package controllers

import (
"bytes"
"context"
"fmt"
"strings"
"text/template"

"github.com/Masterminds/sprig"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -197,7 +201,7 @@ func collectMgmtResources(ctx context.Context, clusterSummary *configv1alpha1.Cl

result := make(map[string]*unstructured.Unstructured)
for i := range clusterSummary.Spec.ClusterProfileSpec.TemplateResourceRefs {
ref := clusterSummary.Spec.ClusterProfileSpec.TemplateResourceRefs[i]
ref := &clusterSummary.Spec.ClusterProfileSpec.TemplateResourceRefs[i]
// If namespace is not defined, default to cluster namespace
namespace := ref.Resource.Namespace
if namespace == "" {
Expand All @@ -208,8 +212,13 @@ func collectMgmtResources(ctx context.Context, clusterSummary *configv1alpha1.Cl
return nil, err
}

instantiatedName, err := getMgmtResourceName(clusterSummary, ref)
if err != nil {
return nil, err
}

var u *unstructured.Unstructured
u, err = dr.Get(ctx, ref.Resource.Name, metav1.GetOptions{})
u, err = dr.Get(ctx, instantiatedName, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
continue
Expand All @@ -222,3 +231,27 @@ func collectMgmtResources(ctx context.Context, clusterSummary *configv1alpha1.Cl

return result, nil
}

// Resources referenced in the management cluster can have their name expressed in function
// of cluster information (clusterNamespace, clusterName, clusterType)
func getMgmtResourceName(clusterSummary *configv1alpha1.ClusterSummary,
ref *configv1alpha1.TemplateResourceRef) (string, error) {

// Accept name that are templates
templateName := getTemplateName(clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName,
string(clusterSummary.Spec.ClusterType))
tmpl, err := template.New(templateName).Option("missingkey=error").Funcs(sprig.FuncMap()).Parse(ref.Resource.Name)
if err != nil {
return "", err
}

var buffer bytes.Buffer

if err := tmpl.Execute(&buffer,
struct{ ClusterNamespace, ClusterName string }{
ClusterNamespace: clusterSummary.Spec.ClusterNamespace,
ClusterName: clusterSummary.Spec.ClusterName}); err != nil {
return "", errors.Wrapf(err, "error executing template")
}
return buffer.String(), nil
}
24 changes: 24 additions & 0 deletions controllers/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,30 @@ var _ = Describe("getClusterProfileOwner ", func() {
Expect(currentClusterSummary).ToNot(BeNil())
Expect(currentClusterSummary.Name).To(Equal(clusterSummary.Name))
})

It("getMgmtResourceName returns the correct name", func() {
ref := &configv1alpha1.TemplateResourceRef{
Resource: corev1.ObjectReference{
Name: "{{ .ClusterNamespace }}-{{ .ClusterName }}",
},
Identifier: randomString(),
}

clusterSummary := &configv1alpha1.ClusterSummary{
ObjectMeta: metav1.ObjectMeta{
Name: "cs" + randomString(),
},
Spec: configv1alpha1.ClusterSummarySpec{
ClusterNamespace: cluster.Namespace,
ClusterName: cluster.Name,
ClusterType: libsveltosv1alpha1.ClusterTypeCapi,
},
}

value, err := controllers.GetMgmtResourceName(clusterSummary, ref)
Expect(err).To(BeNil())
Expect(value).To(Equal(cluster.Namespace + "-" + cluster.Name))
})
})

func getClusterRef(cluster client.Object) *corev1.ObjectReference {
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
github.com/pkg/errors v0.9.1
github.com/projectsveltos/libsveltos v0.15.2
github.com/projectsveltos/libsveltos v0.15.3
github.com/prometheus/client_golang v1.16.0
github.com/spf13/pflag v1.0.5
github.com/yuin/gopher-lua v1.1.0
Expand All @@ -31,8 +31,8 @@ require (
k8s.io/component-base v0.27.3
k8s.io/klog/v2 v2.100.1
k8s.io/utils v0.0.0-20230505201702-9f6742963106
sigs.k8s.io/cluster-api v1.5.0
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/cluster-api v1.5.1
sigs.k8s.io/controller-runtime v0.15.1
sigs.k8s.io/kustomize/api v0.13.2
sigs.k8s.io/kustomize/kyaml v0.14.1
)
Expand Down Expand Up @@ -149,7 +149,7 @@ require (
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.10.0 // indirect
Expand Down
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ github.com/containerd/containerd v1.7.0 h1:G/ZQr3gMZs6ZT0qPUZ15znx5QSdQdASW11nXT
github.com/containerd/containerd v1.7.0/go.mod h1:QfR7Efgb/6X2BDpTPJRvPTYDE9rsF0FsXX9J8sIs/sc=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/coredns/caddy v1.1.0 h1:ezvsPrT/tA/7pYDBZxu0cT0VmWk75AfIaf6GSYCNMf0=
github.com/coredns/corefile-migration v1.0.20 h1:MdOkT6F3ehju/n9tgxlGct8XAajOX2vN+wG7To4BWSI=
github.com/coredns/corefile-migration v1.0.21 h1:W/DCETrHDiFo0Wj03EyMkaQ9fwsmSgqTCQDHpceaSsE=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down Expand Up @@ -557,8 +557,8 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg
github.com/poy/onpar v0.0.0-20200406201722-06f95a1c68e8/go.mod h1:nSbFQvMj97ZyhFRSJYtut+msi4sOY6zJDGCdSc+/rZU=
github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY=
github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg=
github.com/projectsveltos/libsveltos v0.15.2 h1:5xdj4S6gLPY+40zvtqsKeiYvcEl3xQJ/lTSKWxElrlM=
github.com/projectsveltos/libsveltos v0.15.2/go.mod h1:7PaqLwqxsnsG+lV07m4RO4rOg2gKhlmpJVanWcB84JQ=
github.com/projectsveltos/libsveltos v0.15.3 h1:EZLZIYlJMezWD0JTiaY1YDlXDrZIgvtF17ddgPAESEo=
github.com/projectsveltos/libsveltos v0.15.3/go.mod h1:7PaqLwqxsnsG+lV07m4RO4rOg2gKhlmpJVanWcB84JQ=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
Expand Down Expand Up @@ -810,8 +810,8 @@ golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1168,10 +1168,10 @@ oras.land/oras-go v1.2.3/go.mod h1:M/uaPdYklze0Vf3AakfarnpoEckvw0ESbRdN8Z1vdJg=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/cluster-api v1.5.0 h1:pwXvzScbAwnrB7EWHTApzW+VQfrj2OSrWAQDC9+bcbU=
sigs.k8s.io/cluster-api v1.5.0/go.mod h1:ZSEP01t8oT6104gB4ljsOwwp5uJcI8SWy8IFp2HUvrc=
sigs.k8s.io/controller-runtime v0.15.0 h1:ML+5Adt3qZnMSYxZ7gAverBLNPSMQEibtzAgp0UPojU=
sigs.k8s.io/controller-runtime v0.15.0/go.mod h1:7ngYvp1MLT+9GeZ+6lH3LOlcHkp/+tzA/fmHa4iq9kk=
sigs.k8s.io/cluster-api v1.5.1 h1:+oO4EbVQcbBJr5wjqmdjvewPHSTbVLigXZqPk3ZO8t0=
sigs.k8s.io/cluster-api v1.5.1/go.mod h1:EGJUNpFWi7dF426tO8MG/jE+w7T0UO5KyMnOwQ5riUY=
sigs.k8s.io/controller-runtime v0.15.1 h1:9UvgKD4ZJGcj24vefUFgZFP3xej/3igL9BsOUTb/+4c=
sigs.k8s.io/controller-runtime v0.15.1/go.mod h1:7ngYvp1MLT+9GeZ+6lH3LOlcHkp/+tzA/fmHa4iq9kk=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kustomize/api v0.13.2 h1:kejWfLeJhUsTGioDoFNJET5LQe/ajzXhJGYoU+pJsiA=
Expand Down
10 changes: 5 additions & 5 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/onsi/ginkgo/v2 v2.11.0
golang.org/x/oauth2 v0.10.0
k8s.io/client-go v0.27.2
sigs.k8s.io/cluster-api v1.5.0
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230808055612-5bf44d2ffd62
sigs.k8s.io/cluster-api v1.5.1
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230831162448-4332e3a54f00
sigs.k8s.io/controller-tools v0.12.0
sigs.k8s.io/kind v0.20.0
)
Expand All @@ -32,7 +32,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/coredns/caddy v1.1.0 // indirect
github.com/coredns/corefile-migration v1.0.20 // indirect
github.com/coredns/corefile-migration v1.0.21 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/daviddengcn/go-colortext v1.0.0 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
Expand Down Expand Up @@ -124,7 +124,7 @@ require (
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
Expand Down Expand Up @@ -152,7 +152,7 @@ require (
k8s.io/kubectl v0.27.2 // indirect
k8s.io/metrics v0.27.2 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/controller-runtime v0.15.0 // indirect
sigs.k8s.io/controller-runtime v0.15.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.2 // indirect
sigs.k8s.io/kustomize/kustomize/v5 v5.0.1 // indirect
Expand Down
Loading

0 comments on commit d52b44d

Please sign in to comment.