-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f567db6
commit 638f129
Showing
7 changed files
with
373 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package builder | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func extractAndPrepManifestTarball(tarballFile, privateEksDServerDomain, privateEksAServerDomain string) error { | ||
log.Println("Manifest tarball provided, extracting to directory") | ||
manifestDir, err := getManifestRoot() | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving manifest root") | ||
} | ||
if err = extractTarball(tarballFile, manifestDir); err != nil { | ||
return fmt.Errorf("Error extracting tarball: %v", err) | ||
} | ||
|
||
// Replacing eks-a bundles manifest hostname | ||
// These endpoints are used for artifacts like containerd, crictl & etcdadm | ||
// Find all eks-a bundles manifest and replace hostname | ||
files, err := os.ReadDir(manifestDir) | ||
if err != nil { | ||
return err | ||
} | ||
for _, file := range files { | ||
if !file.IsDir() { | ||
// Find EKS-D Manifests and replace prod distro domain with private server's | ||
absFilePath := filepath.Join(manifestDir, file.Name()) | ||
eksDManifestFilePattern := strings.ReplaceAll(eksDistroManifestFileNameFormat, "%s", "*") | ||
eksDMatch, err := filepath.Match(eksDManifestFilePattern, file.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("File: %s, Match: %s, Pattern: %s\n", file.Name(), eksDMatch, eksDManifestFilePattern) | ||
if eksDMatch { | ||
if err = replaceStringInFile(absFilePath, fmt.Sprintf("https://%s", eksDistroProdDomain), privateEksDServerDomain); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Find EKS-A Bundles Manifests and replace prod anywhere domain with private server's | ||
eksABundlesManifestFilePattern := strings.ReplaceAll(eksAnywhereBundlesFileNameFormat, "%s", "*") | ||
eksAMatch, err := filepath.Match(eksABundlesManifestFilePattern, file.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("File: %s, Match: %s, Pattern: %s\n", file.Name(), eksAMatch, eksABundlesManifestFilePattern) | ||
if eksAMatch { | ||
if err = replaceStringInFile(absFilePath, fmt.Sprintf("https://%s", eksAnywhereAssetsProdDomain), privateEksAServerDomain); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func replaceStringInFile(filePath, oldString, newString string) error { | ||
fileContents, err := os.ReadFile(filePath) | ||
if err != nil { | ||
return err | ||
} | ||
replacedString := strings.ReplaceAll(string(fileContents), oldString, newString) | ||
if err = os.Remove(filePath); err != nil { | ||
return err | ||
} | ||
err = os.WriteFile(filePath, []byte(replacedString), 0755) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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
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
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
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
Oops, something went wrong.