Skip to content

Commit 7f3201e

Browse files
authored
fix clm kustomization deployment (#159)
1 parent 01ba5ad commit 7f3201e

File tree

7 files changed

+119
-26
lines changed

7 files changed

+119
-26
lines changed

clm/cmd/apply.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ func newApplyCmd() *cobra.Command {
6060

6161
ownerId := fullName + "/" + namespace + "/" + name
6262

63-
objects, err := manifests.Generate(manifestSources, options.valuesSources, fullName, clnt, namespace, name)
64-
if err != nil {
65-
return err
66-
}
67-
6863
release, err := releaseClient.Get(context.TODO(), namespace, name)
6964
if err != nil {
7065
if apierrors.IsNotFound(err) {
@@ -83,6 +78,11 @@ func newApplyCmd() *cobra.Command {
8378

8479
release.Revision += 1
8580

81+
objects, err := manifests.Generate(manifestSources, options.valuesSources, fullName, clnt, release)
82+
if err != nil {
83+
return err
84+
}
85+
8686
backoff := backoff.New()
8787

8888
var timeout <-chan time.Time
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and component-operator-runtime contributors
3+
SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package manifests
7+
8+
import (
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
11+
"github.com/sap/component-operator-runtime/clm/internal/release"
12+
"github.com/sap/component-operator-runtime/pkg/component"
13+
"github.com/sap/component-operator-runtime/pkg/types"
14+
)
15+
16+
type Component struct {
17+
metav1.PartialObjectMetadata
18+
release *release.Release
19+
values map[string]any
20+
}
21+
22+
var _ component.Component = &Component{}
23+
24+
func (c *Component) GetSpec() types.Unstructurable {
25+
return types.UnstructurableMap(c.values)
26+
}
27+
28+
func (c *Component) GetStatus() *component.Status {
29+
return &component.Status{
30+
// TODO: populate missing fields
31+
// ObservedGeneration
32+
// AppliedGeneration
33+
// LastObservedAt
34+
// LastAppliedAt
35+
// ProcessingDigest
36+
// ProcessingSince
37+
// Conditions
38+
State: c.release.State,
39+
Inventory: c.release.Inventory,
40+
}
41+
}
42+
43+
func componentFromRelease(release *release.Release, values map[string]any) *Component {
44+
return &Component{
45+
PartialObjectMetadata: metav1.PartialObjectMetadata{
46+
TypeMeta: metav1.TypeMeta{
47+
APIVersion: "clm.cs.sap.com/v1alpha1",
48+
Kind: "Component",
49+
},
50+
ObjectMeta: metav1.ObjectMeta{
51+
// TODO: add more metadata (maybe from the configmap backing the release)
52+
Namespace: release.GetNamespace(),
53+
Name: release.GetName(),
54+
},
55+
},
56+
release: release,
57+
values: values,
58+
}
59+
}

clm/internal/manifests/generate.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/client"
1717
kyaml "sigs.k8s.io/yaml"
1818

19+
"github.com/sap/component-operator-runtime/clm/internal/release"
1920
"github.com/sap/component-operator-runtime/pkg/cluster"
2021
"github.com/sap/component-operator-runtime/pkg/component"
2122
"github.com/sap/component-operator-runtime/pkg/manifests"
@@ -24,7 +25,7 @@ import (
2425
"github.com/sap/component-operator-runtime/pkg/types"
2526
)
2627

27-
func Generate(manifestSources []string, valuesSources []string, reconcilerName string, clnt cluster.Client, namespace string, name string) ([]client.Object, error) {
28+
func Generate(manifestSources []string, valuesSources []string, reconcilerName string, clnt cluster.Client, release *release.Release) ([]client.Object, error) {
2829
var allObjects []client.Object
2930
var allValues = make(map[string]any)
3031

@@ -55,9 +56,17 @@ func Generate(manifestSources []string, valuesSources []string, reconcilerName s
5556
return nil, err
5657
}
5758
} else if !info.IsDir() {
58-
return nil, fmt.Errorf("not a directory: %s", path)
59+
tmpdir, err := os.MkdirTemp("", "clm-")
60+
if err != nil {
61+
return nil, err
62+
}
63+
defer os.RemoveAll(tmpdir)
64+
if _, err := copyFile(path, fmt.Sprintf("%s/%s", tmpdir, "resources.yaml")); err != nil {
65+
return nil, err
66+
}
67+
path = tmpdir
5968
}
60-
path, err := filepath.Abs(source)
69+
path, err := filepath.Abs(path)
6170
if err != nil {
6271
return nil, err
6372
}
@@ -82,9 +91,9 @@ func Generate(manifestSources []string, valuesSources []string, reconcilerName s
8291
generateCtx := component.NewContext(context.TODO()).
8392
WithReconcilerName(reconcilerName).
8493
WithClient(clnt).
85-
WithComponent(nil).
94+
WithComponent(componentFromRelease(release, allValues)).
8695
WithComponentDigest("")
87-
objects, err := generator.Generate(generateCtx, namespace, name, types.UnstructurableMap(allValues))
96+
objects, err := generator.Generate(generateCtx, release.GetNamespace(), release.GetName(), types.UnstructurableMap(allValues))
8897
if err != nil {
8998
return nil, err
9099
}

clm/internal/manifests/util.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and component-operator-runtime contributors
3+
SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package manifests
7+
8+
import (
9+
"fmt"
10+
"io"
11+
"os"
12+
)
13+
14+
func copyFile(src, dst string) (int64, error) {
15+
sourceFileStat, err := os.Stat(src)
16+
if err != nil {
17+
return 0, err
18+
}
19+
20+
// TODO: what about symlinks?
21+
if !sourceFileStat.Mode().IsRegular() {
22+
return 0, fmt.Errorf("%s is not a regular file", src)
23+
}
24+
25+
source, err := os.Open(src)
26+
if err != nil {
27+
return 0, err
28+
}
29+
defer source.Close()
30+
31+
destination, err := os.Create(dst)
32+
if err != nil {
33+
return 0, err
34+
}
35+
defer destination.Close()
36+
37+
nBytes, err := io.Copy(destination, source)
38+
return nBytes, err
39+
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ require (
8383
github.com/spf13/cast v1.7.0 // indirect
8484
github.com/x448/float16 v0.8.4 // indirect
8585
github.com/xlab/treeprint v1.2.0 // indirect
86-
go.starlark.net v0.0.0-20240123142251-f86470692795 // indirect
8786
golang.org/x/crypto v0.26.0 // indirect
8887
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
8988
golang.org/x/net v0.28.0 // indirect

go.sum

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1
106106
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
107107
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
108108
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
109-
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
110-
github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
111109
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
112110
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
113111
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -154,8 +152,8 @@ github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3k
154152
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
155153
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
156154
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
157-
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
158-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
155+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
156+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
159157
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
160158
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
161159
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
@@ -166,8 +164,6 @@ github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
166164
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
167165
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
168166
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
169-
go.starlark.net v0.0.0-20240123142251-f86470692795 h1:LmbG8Pq7KDGkglKVn8VpZOZj6vb9b8nKEGcg9l03epM=
170-
go.starlark.net v0.0.0-20240123142251-f86470692795/go.mod h1:LcLNIzVOMp4oV+uusnpk+VU+SzXaJakUuBjoCSWH5dM=
171167
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
172168
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
173169
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
@@ -208,8 +204,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
208204
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
209205
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
210206
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
211-
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
212-
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
213207
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
214208
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
215209
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -245,8 +239,6 @@ k8s.io/apiextensions-apiserver v0.31.1 h1:L+hwULvXx+nvTYX/MKM3kKMZyei+UiSXQWciX/
245239
k8s.io/apiextensions-apiserver v0.31.1/go.mod h1:tWMPR3sgW+jsl2xm9v7lAyRF1rYEK71i9G5dRtkknoQ=
246240
k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U=
247241
k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
248-
k8s.io/cli-runtime v0.30.1 h1:kSBBpfrJGS6lllc24KeniI9JN7ckOOJKnmFYH1RpTOw=
249-
k8s.io/cli-runtime v0.30.1/go.mod h1:zhHgbqI4J00pxb6gM3gJPVf2ysDjhQmQtnTxnMScab8=
250242
k8s.io/cli-runtime v0.31.1 h1:/ZmKhmZ6hNqDM+yf9s3Y4KEYakNXUn5sod2LWGGwCuk=
251243
k8s.io/cli-runtime v0.31.1/go.mod h1:pKv1cDIaq7ehWGuXQ+A//1OIF+7DI+xudXtExMCbe9U=
252244
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
@@ -265,12 +257,8 @@ sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC
265257
sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
266258
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
267259
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
268-
sigs.k8s.io/kustomize/api v0.17.3 h1:6GCuHSsxq7fN5yhF2XrC+AAr8gxQwhexgHflOAD/JJU=
269-
sigs.k8s.io/kustomize/api v0.17.3/go.mod h1:TuDH4mdx7jTfK61SQ/j1QZM/QWR+5rmEiNjvYlhzFhc=
270260
sigs.k8s.io/kustomize/api v0.18.0 h1:hTzp67k+3NEVInwz5BHyzc9rGxIauoXferXyjv5lWPo=
271261
sigs.k8s.io/kustomize/api v0.18.0/go.mod h1:f8isXnX+8b+SGLHQ6yO4JG1rdkZlvhaCf/uZbLVMb0U=
272-
sigs.k8s.io/kustomize/kyaml v0.17.2 h1:+AzvoJUY0kq4QAhH/ydPHHMRLijtUKiyVyh7fOSshr0=
273-
sigs.k8s.io/kustomize/kyaml v0.17.2/go.mod h1:9V0mCjIEYjlXuCdYsSXvyoy2BTsLESH7TlGV81S282U=
274262
sigs.k8s.io/kustomize/kyaml v0.18.1 h1:WvBo56Wzw3fjS+7vBjN6TeivvpbW9GmRaWZ9CIVmt4E=
275263
sigs.k8s.io/kustomize/kyaml v0.18.1/go.mod h1:C3L2BFVU1jgcddNBE1TxuVLgS46TjObMwW5FT9FcjYo=
276264
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=

pkg/manifests/kustomize/generator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ func (g *KustomizeGenerator) Generate(ctx context.Context, namespace string, nam
198198
if err != nil {
199199
return nil, err
200200
}
201-
202201
serverInfo, err := clnt.DiscoveryClient().ServerVersion()
203202
if err != nil {
204203
return nil, err

0 commit comments

Comments
 (0)