Skip to content

Commit

Permalink
Merge branch 'main' into refactor-init-zarf-state
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinAbro321 authored Aug 5, 2024
2 parents 043670b + 3d9e56e commit e1f7ff5
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 170 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

# Upload the contents of the build directory for later stages to use
- name: Upload build artifacts
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: build-artifacts
path: build/
Expand Down Expand Up @@ -186,7 +186,7 @@ jobs:
HOMEBREW_TAP_GITHUB_TOKEN: ${{ steps.brew-tap-token.outputs.token }}

- name: Save CVE report
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: cve-report
path: build/zarf-known-cves.csv
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: SARIF file
path: results.sarif
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-bigbang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:

# Upload the contents of the build directory for later stages to use
- name: Upload build artifacts
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: build-artifacts
path: build/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

# Upload the contents of the build directory for later stages to use
- name: Upload build artifacts
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: build-artifacts
path: build/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

# Upload the contents of the build directory for later stages to use
- name: Upload build artifacts
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: build-artifacts
path: build/
Expand Down
2 changes: 1 addition & 1 deletion examples/podinfo-flux/git/podinfo-kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: podinfo-git
Expand Down
2 changes: 1 addition & 1 deletion examples/podinfo-flux/git/podinfo-source.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: podinfo
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ var createPackageRegistryToken = &cobra.Command{
}

// If we are setup to use an internal artifact server, create the artifact registry token
if state.ArtifactServer.InternalServer {
if state.ArtifactServer.IsInternal() {
tunnel, err := c.NewTunnel(cluster.ZarfNamespaceName, cluster.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/tools/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var updateCredsCmd = &cobra.Command{
}

// Update artifact token (if internal)
if slices.Contains(args, message.ArtifactKey) && newState.ArtifactServer.PushToken == "" && newState.ArtifactServer.InternalServer {
if slices.Contains(args, message.ArtifactKey) && newState.ArtifactServer.PushToken == "" && newState.ArtifactServer.IsInternal() {
tunnel, err := c.NewTunnel(cluster.ZarfNamespaceName, cluster.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
if err != nil {
return err
Expand Down Expand Up @@ -186,14 +186,14 @@ var updateCredsCmd = &cobra.Command{
// Update Zarf 'init' component Helm releases if present
h := helm.NewClusterOnly(&types.PackagerConfig{}, template.GetZarfVariableConfig(), newState, c)

if slices.Contains(args, message.RegistryKey) && newState.RegistryInfo.InternalRegistry {
if slices.Contains(args, message.RegistryKey) && newState.RegistryInfo.IsInternal() {
err = h.UpdateZarfRegistryValues(ctx)
if err != nil {
// Warn if we couldn't actually update the registry (it might not be installed and we should try to continue)
message.Warnf(lang.CmdToolsUpdateCredsUnableUpdateRegistry, err.Error())
}
}
if slices.Contains(args, message.GitKey) && newState.GitServer.InternalServer {
if slices.Contains(args, message.GitKey) && newState.GitServer.IsInternal() {
tunnel, err := c.NewTunnel(cluster.ZarfNamespaceName, cluster.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion src/internal/agent/hooks/flux-helmrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func mutateHelmRepo(ctx context.Context, r *v1.AdmissionRequest, cluster *cluste

message.Debugf("original HelmRepo URL of (%s) got mutated to (%s)", src.Spec.URL, patchedURL)

patches := populateHelmRepoPatchOperations(patchedURL, zarfState.RegistryInfo.InternalRegistry)
patches := populateHelmRepoPatchOperations(patchedURL, zarfState.RegistryInfo.IsInternal())

patches = append(patches, getLabelPatch(src.Labels))

Expand Down
2 changes: 1 addition & 1 deletion src/internal/agent/hooks/flux-ocirepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func mutateOCIRepo(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster

message.Debugf("original OCIRepo URL of (%s) got mutated to (%s)", src.Spec.URL, patchedURL)

patches := populateOCIRepoPatchOperations(patchedURL, zarfState.RegistryInfo.InternalRegistry, patchedRef)
patches := populateOCIRepoPatchOperations(patchedURL, zarfState.RegistryInfo.IsInternal(), patchedRef)

patches = append(patches, getLabelPatch(src.Labels))
return &operations.Result{
Expand Down
2 changes: 1 addition & 1 deletion src/internal/packager/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func GetZarfTemplates(componentName string, state *types.ZarfState) (templateMap
// generateHtpasswd returns an htpasswd string for the current state's RegistryInfo.
func generateHtpasswd(regInfo *types.RegistryInfo) (string, error) {
// Only calculate this for internal registries to allow longer external passwords
if regInfo.InternalRegistry {
if regInfo.IsInternal() {
pushUser, err := utils.GetHtpasswdString(regInfo.PushUsername, regInfo.PushPassword)
if err != nil {
return "", fmt.Errorf("error generating htpasswd string: %w", err)
Expand Down
33 changes: 5 additions & 28 deletions src/pkg/cluster/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,14 @@ func MergeZarfState(oldState *types.ZarfState, initOptions types.ZarfInitOptions
if slices.Contains(services, message.RegistryKey) {
// TODO: Replace use of reflections with explicit setting
newState.RegistryInfo = helpers.MergeNonZero(newState.RegistryInfo, initOptions.RegistryInfo)
// Set the state of the internal registry if it has changed
// TODO: Internal registry should be a function of the address and not a property.
if newState.RegistryInfo.Address == fmt.Sprintf("%s:%d", helpers.IPV4Localhost, newState.RegistryInfo.NodePort) {
newState.RegistryInfo.InternalRegistry = true
} else {
newState.RegistryInfo.InternalRegistry = false
}

// Set the new passwords if they should be autogenerated
if newState.RegistryInfo.PushPassword == oldState.RegistryInfo.PushPassword && oldState.RegistryInfo.InternalRegistry {
if newState.RegistryInfo.PushPassword == oldState.RegistryInfo.PushPassword && oldState.RegistryInfo.IsInternal() {
if newState.RegistryInfo.PushPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil {
return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err)
}
}
if newState.RegistryInfo.PullPassword == oldState.RegistryInfo.PullPassword && oldState.RegistryInfo.InternalRegistry {
if newState.RegistryInfo.PullPassword == oldState.RegistryInfo.PullPassword && oldState.RegistryInfo.IsInternal() {
if newState.RegistryInfo.PullPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil {
return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err)
}
Expand All @@ -327,21 +320,13 @@ func MergeZarfState(oldState *types.ZarfState, initOptions types.ZarfInitOptions
// TODO: Replace use of reflections with explicit setting
newState.GitServer = helpers.MergeNonZero(newState.GitServer, initOptions.GitServer)

// Set the state of the internal git server if it has changed
// TODO: Internal server should be a function of the address and not a property.
if newState.GitServer.Address == types.ZarfInClusterGitServiceURL {
newState.GitServer.InternalServer = true
} else {
newState.GitServer.InternalServer = false
}

// Set the new passwords if they should be autogenerated
if newState.GitServer.PushPassword == oldState.GitServer.PushPassword && oldState.GitServer.InternalServer {
if newState.GitServer.PushPassword == oldState.GitServer.PushPassword && oldState.GitServer.IsInternal() {
if newState.GitServer.PushPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil {
return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err)
}
}
if newState.GitServer.PullPassword == oldState.GitServer.PullPassword && oldState.GitServer.InternalServer {
if newState.GitServer.PullPassword == oldState.GitServer.PullPassword && oldState.GitServer.IsInternal() {
if newState.GitServer.PullPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil {
return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err)
}
Expand All @@ -351,16 +336,8 @@ func MergeZarfState(oldState *types.ZarfState, initOptions types.ZarfInitOptions
// TODO: Replace use of reflections with explicit setting
newState.ArtifactServer = helpers.MergeNonZero(newState.ArtifactServer, initOptions.ArtifactServer)

// Set the state of the internal artifact server if it has changed
// TODO: Internal server should be a function of the address and not a property.
if newState.ArtifactServer.Address == types.ZarfInClusterArtifactServiceURL {
newState.ArtifactServer.InternalServer = true
} else {
newState.ArtifactServer.InternalServer = false
}

// Set an empty token if it should be autogenerated
if newState.ArtifactServer.PushToken == oldState.ArtifactServer.PushToken && oldState.ArtifactServer.InternalServer {
if newState.ArtifactServer.PushToken == oldState.ArtifactServer.PushToken && oldState.ArtifactServer.IsInternal() {
newState.ArtifactServer.PushToken = ""
}
}
Expand Down
Loading

0 comments on commit e1f7ff5

Please sign in to comment.