-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kubernetes make target to generate custom data (#159)
* kubernetes make target to generate custom data * removed go.mod
- Loading branch information
Showing
8 changed files
with
85 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
**/.DS_Store | ||
**/_out | ||
go.mod |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.PHONY: build-encoder | ||
build-encoder: | ||
go build -o _out/encoder hack/encode/main.go | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf _out | ||
|
||
.PHONY: generate | ||
generate: clean build-encoder | ||
hack/generate.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/msazurestackworkloads/azurestack-gallery/kubernetes | ||
|
||
go 1.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"encoding/base64" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
scriptstring := getBase64CustomScript(os.Args[1]) | ||
customerString := getSingleLine("hack/encode/template.yaml", scriptstring) | ||
fmt.Print(fmt.Sprintf("[base64(concat('%s'))]", customerString)) | ||
} | ||
|
||
// getBase64CustomScript will return a base64 of the CSE | ||
func getSingleLine(csFilename string, scriptstring string) string { | ||
b, err := ioutil.ReadFile(csFilename) | ||
if err != nil { | ||
// this should never happen and this is a bug | ||
panic(fmt.Sprintf("BUG: %s", err.Error())) | ||
} | ||
// translate the parameters | ||
csStr := string(b) | ||
csStr = strings.Replace(csStr, "SCRIPT_PLACEHOLDER", scriptstring, -1) | ||
csStr = strings.Replace(csStr, "\r\n", "\n", -1) | ||
return escapeSingleLine(csStr) | ||
} | ||
|
||
func escapeSingleLine(escapedStr string) string { | ||
// template.JSEscapeString leaves undesirable chars that don't work with pretty print | ||
escapedStr = strings.Replace(escapedStr, "\\", "\\\\", -1) | ||
escapedStr = strings.Replace(escapedStr, "\r\n", "\\n", -1) | ||
escapedStr = strings.Replace(escapedStr, "\n", "\\n", -1) | ||
escapedStr = strings.Replace(escapedStr, "!!binary |", "!!binary \\|", -1) | ||
escapedStr = strings.Replace(escapedStr, "\"", "\\\"", -1) | ||
return escapedStr | ||
} | ||
|
||
// getBase64CustomScript will return a base64 of the CSE | ||
func getBase64CustomScript(csFilename string) string { | ||
b, err := ioutil.ReadFile(csFilename) | ||
if err != nil { | ||
// this should never happen and this is a bug | ||
panic(fmt.Sprintf("BUG: %s", err.Error())) | ||
} | ||
// translate the parameters | ||
csStr := string(b) | ||
csStr = strings.Replace(csStr, "\r\n", "\n", -1) | ||
return getBase64CustomScriptFromStr(csStr) | ||
} | ||
|
||
// getBase64CustomScript will return a base64 of the CSE | ||
func getBase64CustomScriptFromStr(str string) string { | ||
var gzipB bytes.Buffer | ||
w := gzip.NewWriter(&gzipB) | ||
w.Write([]byte(str)) | ||
w.Close() | ||
return base64.StdEncoding.EncodeToString(gzipB.Bytes()) | ||
} |
4 changes: 2 additions & 2 deletions
4
.pipeline/assets/encoding/dvm_cloud_init.t → kubernetes/hack/encode/template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#cloud-config | ||
|
||
write_files: | ||
- path: "/opt/azure/containers/script.sh" | ||
- path: /opt/azure/containers/script.sh | ||
permissions: "0744" | ||
encoding: gzip | ||
owner: "root" | ||
owner: root:root | ||
content: !!binary | | ||
SCRIPT_PLACEHOLDER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
mkdir -p _out | ||
_out/encoder template/DeploymentTemplates/script.sh > _out/customdata.txt |