Skip to content

Commit 9f435e9

Browse files
Push built image to the S3
Signed-off-by: michal.gubricky <michal.gubricky@dnation.cloud>
1 parent 228a0f2 commit 9f435e9

File tree

338 files changed

+90955
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

338 files changed

+90955
-726
lines changed

csctlopenstack/csctlopenstack_main.go

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,30 @@ limitations under the License.
1818
package main
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"os"
2324
"os/exec"
2425
"path/filepath"
2526
"strings"
2627

2728
csctlclusterstack "github.com/SovereignCloudStack/csctl/pkg/clusterstack"
29+
minio "github.com/minio/minio-go/v7"
30+
"github.com/minio/minio-go/v7/pkg/credentials"
31+
"gopkg.in/yaml.v2"
2832
)
2933

34+
// RegistryConfig represents the structure of the registry.yaml file.
35+
type RegistryConfig struct {
36+
Type string `yaml:"type"`
37+
Config struct {
38+
Endpoint string `yaml:"endpoint"`
39+
Bucket string `yaml:"bucket"`
40+
AccessKey string `yaml:"accessKey"`
41+
SecretKey string `yaml:"secretKey"`
42+
} `yaml:"config"`
43+
}
44+
3045
const provider = "openstack"
3146

3247
func usage() {
@@ -83,6 +98,7 @@ func main() {
8398

8499
if _, err := os.Stat(packerImagePath); err == nil {
85100
fmt.Println("Running packer build...")
101+
// #nosec G204
86102
cmd := exec.Command("packer", "build", packerImagePath)
87103
cmd.Stdout = os.Stdout
88104
cmd.Stderr = os.Stderr
@@ -92,11 +108,20 @@ func main() {
92108
}
93109
fmt.Println("Packer build completed successfully.")
94110

95-
// // Push the built image to S3
96-
// if err := pushToS3(releaseDir, *image); err != nil {
97-
// fmt.Printf("Error pushing image to S3: %v\n", err)
98-
// os.Exit(1)
99-
// }
111+
registryConfig := filepath.Join(clusterStackPath, "node-images", "registry.yaml")
112+
// Get the current working directory
113+
currentDir, err := os.Getwd()
114+
if err != nil {
115+
fmt.Printf("Error getting current working directory: %v\n", err)
116+
os.Exit(1)
117+
}
118+
ouputImageDir := filepath.Join(currentDir, "output", *image)
119+
// Push the built image to S3
120+
if err := pushToS3(ouputImageDir, *image, registryConfig); err != nil {
121+
fmt.Printf("Error pushing image to S3: %v\n", err)
122+
os.Exit(1)
123+
}
124+
// TODO: create node-images.yaml in releaseDir after building and pushing image to registry were successful
100125
} else {
101126
fmt.Printf("Image folder %s does not exist\n", packerImagePath)
102127
}
@@ -108,3 +133,49 @@ func main() {
108133
fmt.Println("Unknown method:", method)
109134
}
110135
}
136+
137+
func pushToS3(filePath, fileName, configFilePath string) error {
138+
// Load configuration from YAML file
139+
// #nosec G304
140+
configFile, err := os.Open(configFilePath)
141+
if err != nil {
142+
return fmt.Errorf("error opening config file: %w", err)
143+
}
144+
defer configFile.Close()
145+
146+
var registryConfig RegistryConfig
147+
decoder := yaml.NewDecoder(configFile)
148+
if err := decoder.Decode(&registryConfig); err != nil {
149+
return fmt.Errorf("error decoding config file: %w", err)
150+
}
151+
152+
// Initialize Minio client
153+
minioClient, err := minio.New(registryConfig.Config.Endpoint, &minio.Options{
154+
Creds: credentials.NewStaticV4(registryConfig.Config.AccessKey, registryConfig.Config.SecretKey, ""),
155+
Secure: true,
156+
})
157+
if err != nil {
158+
return fmt.Errorf("error initializing Minio client: %w", err)
159+
}
160+
161+
// Open file to upload
162+
// #nosec G304
163+
file, err := os.Open(filePath)
164+
if err != nil {
165+
return fmt.Errorf("error opening file: %w", err)
166+
}
167+
defer file.Close()
168+
169+
// Get file info
170+
fileInfo, err := file.Stat()
171+
if err != nil {
172+
return fmt.Errorf("error getting file info: %w", err)
173+
}
174+
175+
// Upload file to bucket
176+
_, err = minioClient.PutObject(context.Background(), registryConfig.Config.Bucket, fileName, file, fileInfo.Size(), minio.PutObjectOptions{})
177+
if err != nil {
178+
return fmt.Errorf("error uploading file: %w", err)
179+
}
180+
return nil
181+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
values: |
2+
metrics-server:
3+
commonLabels:
4+
domain: "{{ .Cluster.spec.controlPlaneEndpoint.host }}"
5+
clusterAddonVersion: "v2"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: metrics-server
3+
repository: https://kubernetes-sigs.github.io/metrics-server/
4+
version: 3.11.0
5+
digest: sha256:d92caa34d06b047b0390aa33a6f5d15d4fe0566143625204ebbbc69085133c4e
6+
generated: "2023-09-12T12:02:23.747094767+02:00"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v2
2+
dependencies:
3+
- alias: metrics-server
4+
name: metrics-server
5+
repository: https://kubernetes-sigs.github.io/metrics-server/
6+
version: 3.11.0
7+
description: 'This chart installs and configures: * Openstack Ferrol Cluster Class '
8+
maintainers:
9+
- email: info@syself.com
10+
name: Syself
11+
url: https://github.com/syself
12+
name: openstack-ferrol-1-27-cluster-addon
13+
type: application
14+
version: << .ClusterAddonVersion >>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
annotations:
2+
artifacthub.io/changes: |
3+
- kind: added
4+
description: "Added default Metrics Server resource requests."
5+
- kind: changed
6+
description: "Updated the Metrics Server OCI image to v0.6.3."
7+
- kind: changed
8+
description: "Updated the addon resizer OCI image to v1.8.19."
9+
- kind: changed
10+
description: "Changed the default addon resizer nanny resource configuration to match the documented Metrics Server autoscaling values."
11+
apiVersion: v2
12+
appVersion: 0.6.4
13+
description: Metrics Server is a scalable, efficient source of container resource
14+
metrics for Kubernetes built-in autoscaling pipelines.
15+
home: https://github.com/kubernetes-sigs/metrics-server
16+
icon: https://avatars.githubusercontent.com/u/36015203?s=400&v=4
17+
keywords:
18+
- kubernetes
19+
- metrics-server
20+
- metrics
21+
maintainers:
22+
- name: stevehipwell
23+
url: https://github.com/stevehipwell
24+
- name: krmichel
25+
url: https://github.com/krmichel
26+
- name: endrec
27+
url: https://github.com/endrec
28+
name: metrics-server
29+
sources:
30+
- https://github.com/kubernetes-sigs/metrics-server
31+
type: application
32+
version: 3.11.0

0 commit comments

Comments
 (0)