Skip to content

Commit f56e0b1

Browse files
authored
Merge pull request #83 from google/caramilk
garyb/ft_istiovs
2 parents 1fcfcec + bfa1071 commit f56e0b1

File tree

13 files changed

+210
-45
lines changed

13 files changed

+210
-45
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*.swp
77
.DS_Store
88
**/.DS_Store
9-
shifter
109
out/
1110
*.swp
1211
shifter_linux_*
@@ -17,3 +16,4 @@ data**
1716
.vscode
1817
*.zip
1918
data**
19+
caramilk

shifter/generators/generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func NewGenerator(outputType string, name string, input []lib.K8sobject, paramet
4040

4141
switch outputType {
4242
case "yaml":
43-
return generator.Yaml("", generator.Input.Object)
43+
return generator.Yaml(name, generator.Input.Object)
4444
case "helm":
45-
return generator.Helm("", generator.Input.Object, generator.Input.Parameters)
45+
return generator.Helm(name, generator.Input.Object, generator.Input.Parameters)
4646
}
4747

4848
return nil

shifter/generators/yaml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (generator *Generator) Yaml(name string, objects []lib.K8sobject) []lib.Con
2626
var converted []lib.Converted
2727

2828
for _, v := range objects {
29-
kind := fmt.Sprintf("%v", v.Kind)
29+
//kind := fmt.Sprintf("%v", v.Kind)
3030
buff := new(bytes.Buffer)
3131
writer := bufio.NewWriter(buff)
3232

@@ -38,7 +38,7 @@ func (generator *Generator) Yaml(name string, objects []lib.K8sobject) []lib.Con
3838
writer.Flush()
3939

4040
var result lib.Converted
41-
result.Name = kind
41+
result.Name = name
4242
result.Path = "/"
4343
result.Payload = *buff
4444

shifter/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ require (
1616
golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5
1717
google.golang.org/api v0.66.0
1818
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
19+
istio.io/api v0.0.0-20220512181135-e8ec1e1d89de
20+
istio.io/client-go v1.14.0
1921
k8s.io/api v0.24.0
2022
k8s.io/apimachinery v0.24.0
2123
k8s.io/client-go v0.24.0

shifter/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,10 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
995995
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
996996
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
997997
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
998+
istio.io/api v0.0.0-20220512181135-e8ec1e1d89de h1:xYxUL/LyuJ5yb0o/d2GXseYjx9HIBpLHLArp2Zd8d+M=
999+
istio.io/api v0.0.0-20220512181135-e8ec1e1d89de/go.mod h1:00myJeQGWma4Y5pboJ+MM4P2uqEWulKA1duC8kYN5Wo=
1000+
istio.io/client-go v1.14.0 h1:KKXMnxXx3U2866OP8FBYlJhjKdI3yIUQnt8L6hSzDHE=
1001+
istio.io/client-go v1.14.0/go.mod h1:C7K0CKQlvY84yQKkZhxQbD1riqvnsgXJm3jF5GOmzNg=
9981002
k8s.io/api v0.23.0/go.mod h1:8wmDdLBHBNxtOIytwLstXt5E9PddnZb0GaMcqsvDBpg=
9991003
k8s.io/api v0.24.0 h1:J0hann2hfxWr1hinZIDefw7Q96wmCBx6SSB8IY0MdDg=
10001004
k8s.io/api v0.24.0/go.mod h1:5Jl90IUrJHUJYEMANRURMiVvJ0g7Ax7r3R1bqO8zx8I=

shifter/inputs/yaml.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ package input
1616
import (
1717
"bytes"
1818
"fmt"
19+
gyaml "github.com/ghodss/yaml"
20+
yaml "gopkg.in/yaml.v3"
1921
"io"
2022
"io/ioutil"
2123
"log"
2224
"os"
2325
"shifter/lib"
2426
"shifter/processor"
2527
"strings"
26-
27-
gyaml "github.com/ghodss/yaml"
28-
yaml "gopkg.in/yaml.v3"
2928
)
3029

3130
type Spec struct {

shifter/ops/convert.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,20 @@ func (converter *Converter) ConvertFiles() {
9292
switch converter.InputType {
9393
case "yaml":
9494
sourceFile := inputs.Yaml(file.Content, converter.Flags)
95-
r = generator.NewGenerator(converter.Generator, "test", sourceFile, nil)
95+
log.Println(file.Filename)
96+
r = generator.NewGenerator(converter.Generator, file.Filename, sourceFile, nil)
9697
case "template":
9798
sourceFile, values := inputs.Template(file.Content, converter.Flags)
98-
r = generator.NewGenerator(converter.Generator, "test", sourceFile, values)
99+
r = generator.NewGenerator(converter.Generator, file.Filename, sourceFile, values)
99100
}
100101

101102
//outputFileName := fmt.Sprint(idx)
102103
for k := range r {
103104
fileObj := &FileObject{
104-
StorageType: file.StorageType,
105-
SourcePath: (converter.OutputPath + "/" + r[k].Path + r[k].Name + filepath.Ext(file.SourcePath)),
106-
Filename: r[k].Name,
105+
StorageType: file.StorageType,
106+
//SourcePath: (converter.OutputPath + "/" + r[k].Path + r[k].Name + filepath.Ext(file.SourcePath)),
107+
SourcePath: (converter.OutputPath + "/" + r[k].Path + r[k].Name),
108+
Filename: file.Filename,
107109
Ext: filepath.Ext(file.SourcePath),
108110
Content: r[k].Payload,
109111
ContentLength: file.ContentLength,

shifter/ops/local.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ import (
2323
func (fileObj *FileObject) WriteLCLFile() {
2424

2525
if _, err := os.Stat(fileObj.SourcePath); os.IsNotExist(err) {
26-
os.MkdirAll(filepath.Dir(fileObj.SourcePath), 0700) // Create your file
26+
os.MkdirAll(filepath.Dir(fileObj.SourcePath), 0700) // Create output directory
2727
}
2828

2929
// Create New File
30-
f, err := os.Create(fileObj.SourcePath)
30+
f, err := os.OpenFile(fileObj.SourcePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0700)
3131
if err != nil {
3232
log.Println(err)
3333
return
3434
}
3535
defer f.Close()
36+
f.WriteString("---\n")
3637
// Write the Bytes Buffer to File
3738
_, err = f.Write(fileObj.Content.Bytes())
3839
if err != nil {
@@ -91,6 +92,7 @@ func ProcessLCLPath(path string) ([]*FileObject, error) {
9192
StorageType: LCL,
9293
SourcePath: filePath,
9394
Ext: filepath.Ext(filePath),
95+
Filename: filepath.Base(filePath),
9496
}
9597
// Add File Object to Array of Files
9698
files = append(files, fileObj)
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,11 @@ type Converter struct {
3535
}
3636

3737
type FileObject struct {
38-
UUID string // Unique ID of the Run
39-
StorageType string // GCS or LCL Storage
40-
SourcePath string // Bucket or Local Path
41-
Ext string // File Extention
42-
43-
//Root string // Root Directory "/data" LCL Storage
44-
//Bucket string // Root Bucket Nmae GCS Storage
45-
//Path string // Sub Path ["raw", "output"]
46-
Filename string // Filename
47-
38+
UUID string // Unique ID of the Run
39+
StorageType string // GCS or LCL Storage
40+
SourcePath string // Bucket or Local Path
41+
Ext string // File Extention
42+
Filename string // Filename
4843
Content bytes.Buffer // Content as Bytes Buffer
4944
ContentLength int // Content Length (len(bytes.buffer))
5045
}

shifter/processor/deployment.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
copyright 2019 google llc
3+
licensed under the apache license, version 2.0 (the "license");
4+
you may not use this file except in compliance with the license.
5+
you may obtain a copy of the license at
6+
http://www.apache.org/licenses/license-2.0
7+
unless required by applicable law or agreed to in writing, software
8+
distributed under the license is distributed on an "as is" basis,
9+
without warranties or conditions of any kind, either express or implied.
10+
see the license for the specific language governing permissions and
11+
limitations under the license.
12+
*/
13+
14+
package processor
15+
16+
import (
17+
appsv1 "k8s.io/api/apps/v1"
18+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
)
20+
21+
func convertDeploymentToDeployment(OSDeployment appsv1.Deployment, flags map[string]string) appsv1.Deployment {
22+
deployment := &appsv1.Deployment{
23+
TypeMeta: metav1.TypeMeta{
24+
Kind: "Deployment",
25+
APIVersion: "apps/v1",
26+
},
27+
ObjectMeta: OSDeployment.ObjectMeta,
28+
Spec: OSDeployment.Spec,
29+
}
30+
31+
return *deployment
32+
}

0 commit comments

Comments
 (0)