Skip to content

Commit

Permalink
remove other Zarf init
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
  • Loading branch information
AustinAbro321 committed Aug 5, 2024
1 parent 1895097 commit bec4929
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 43 deletions.
6 changes: 1 addition & 5 deletions src/pkg/cluster/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO
return fmt.Errorf("unable get default Zarf service account: %w", err)
}

err = initOptions.GitServer.FillInEmptyPullValues()
if err != nil {
return err
}
state.GitServer = initOptions.GitServer
state.GitServer = initOptions.GitServer.FillInEmptyPullValues()
err = initOptions.RegistryInfo.FillInEmptyValues()
if err != nil {
return err
Expand Down
8 changes: 0 additions & 8 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,6 @@ func (p *Packager) deployInitComponent(ctx context.Context, component types.Zarf
p.cfg.InitOpts.ApplianceMode = true
}

// Always init the state before the first component that requires the cluster (on most deployments, the zarf-seed-registry)
if component.RequiresCluster() && p.state == nil {
err = p.cluster.InitZarfState(ctx, p.cfg.InitOpts)
if err != nil {
return nil, fmt.Errorf("unable to initialize Zarf state: %w", err)
}
}

if hasExternalRegistry && (isSeedRegistry || isInjector || isRegistry) {
message.Notef("Not deploying the component (%s) since external registry information was provided during `zarf init`", component.Name)
return nil, nil
Expand Down
35 changes: 5 additions & 30 deletions src/types/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,44 +163,19 @@ func GenerateNewInternalGitServerInfo() (GitServerInfo, error) {
}

// FillInEmptyPullValues sets every necessary value that's currently empty to a reasonable default
// TODO write tests
func (gs *GitServerInfo) FillInEmptyPullValues() error {
func (gs GitServerInfo) FillInEmptyPullValues() GitServerInfo {
if gs.Address == "" || gs.PushPassword == "" || gs.PushUsername == "" {
return nil
return gs
}

var err error
// Set default svc url if an external repository was not provided
if gs.Address == "" {
gs.Address = ZarfInClusterGitServiceURL
}

// Generate a push-user password if not provided by init flag
if gs.PushPassword == "" {
if gs.PushPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil {
return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err)
}
}

// Set read-user information if using an internal repository, otherwise copy from the push-user
if gs.PullUsername == "" {
if gs.IsInternal() {
gs.PullUsername = ZarfGitReadUser
} else {
gs.PullUsername = gs.PushUsername
}
gs.PullUsername = gs.PushUsername
}

if gs.PullPassword == "" {
if gs.IsInternal() {
if gs.PullPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil {
return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err)
}
} else {
gs.PullPassword = gs.PushPassword
}
gs.PullPassword = gs.PushPassword
}
return nil
return gs
}

// ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to.
Expand Down

0 comments on commit bec4929

Please sign in to comment.