Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update gitea chart from 8.3.0 to 10.0.0 #2123

Merged
merged 57 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
329fce1
chore: update gitea chart version
TristanHoladay Oct 31, 2023
87a753a
wip: refactoring gitea-values and zarf.yaml
TristanHoladay Nov 1, 2023
eb9f0c6
Merge branch 'defenseunicorns:main' into gitea-chart-update
TristanHoladay Nov 2, 2023
41de1bb
wip: set git-server replicaCount back to zarf var.
TristanHoladay Nov 2, 2023
1b61a42
Merge branch 'main' into gitea-chart-update
Racer159 Nov 6, 2023
ba398ce
wip: update expected gitea version for create_sbom_test
TristanHoladay Nov 6, 2023
14e4778
wip: added scope to Artifact token to read:user
TristanHoladay Nov 7, 2023
b97277f
Merge branch 'main' into gitea-chart-update
TristanHoladay Nov 7, 2023
ab28c3c
wip: updated gitea config values to better match recommended configur…
TristanHoladay Nov 9, 2023
bbe003f
wip: merged main and resolved conflict in gitea zarf.yaml
TristanHoladay Nov 9, 2023
9c50d16
Merge branch 'defenseunicorns:main' into gitea-chart-update
TristanHoladay Nov 15, 2023
cf44d56
Merge branch 'defenseunicorns:main' into gitea-chart-update
TristanHoladay Nov 16, 2023
087d381
wip: set existing server pvc name default to pvc name from 8.3.0; add…
TristanHoladay Nov 17, 2023
97fcf40
wip: iterating on updatig gitea creds via api instead of updated helm…
TristanHoladay Nov 17, 2023
ba3f764
wip: merged main and resolved
TristanHoladay Nov 27, 2023
00cd24c
wip: update-creds api calls refactors
TristanHoladay Nov 27, 2023
48558c6
wip: removed has read only user check from CreateReadOnlyUser()
TristanHoladay Nov 27, 2023
3c48cad
Merge branch 'defenseunicorns:main' into gitea-chart-update
TristanHoladay Nov 27, 2023
b70d100
wip: revert zarf var for gitea claim name to git_server_existing_pvc
TristanHoladay Nov 27, 2023
8613702
wip: added comments to new gitea.go methods for updating users
TristanHoladay Nov 27, 2023
a1e832f
wip: removed comment from gitea zarf.yaml
TristanHoladay Nov 27, 2023
e826833
Merge branch 'main' into gitea-chart-update
TristanHoladay Nov 27, 2023
9cfc214
Merge branch 'main' into gitea-chart-update
TristanHoladay Nov 29, 2023
ba579f0
wip: merge main and resolve
TristanHoladay Nov 30, 2023
5ed83ae
wip: fix h.cfg case typo
TristanHoladay Nov 30, 2023
9d2cf21
Merge branch 'main' into gitea-chart-update
TristanHoladay Dec 1, 2023
bea7886
wip: refactored UpdateZarfGiteaValues() and moved to gitea.go; refact…
TristanHoladay Dec 6, 2023
be43800
Merge branch 'main' into gitea-chart-update
TristanHoladay Dec 6, 2023
99304c9
wip: add comment to UpdateGitUser() since it is exported
TristanHoladay Dec 6, 2023
7716b62
Merge branch 'main' into gitea-chart-update
TristanHoladay Dec 8, 2023
d311871
Merge branch 'main' into gitea-chart-update
Racer159 Dec 11, 2023
06feb72
wip: adding read and write package scopes for git token
TristanHoladay Dec 11, 2023
1066387
Merge branch 'main' into gitea-chart-update
TristanHoladay Dec 12, 2023
f778568
wip: rename UpdateZarfGiteaValues to UpdateZarfGiteaUsers
TristanHoladay Dec 12, 2023
5fb6b3f
Merge branch 'main' into gitea-chart-update
TristanHoladay Dec 13, 2023
ee4f876
Merge branch 'main' into gitea-chart-update
Racer159 Dec 15, 2023
59bb085
Merge branch 'main' into gitea-chart-update
Racer159 Dec 15, 2023
b127bb2
wip: create zarf internal update-gitea-pvc process
TristanHoladay Dec 15, 2023
4351dad
wip: adding roll back to update-gitea-pvc cmd
TristanHoladay Dec 15, 2023
ebfd7cd
wip: fix testing bug
TristanHoladay Dec 15, 2023
29f2b27
wip: fix UpdateGiteaPVC() custom claim logic; refactor AddLabelsAndAn…
TristanHoladay Dec 15, 2023
f263b22
Merge branch 'main' into gitea-chart-update
Racer159 Dec 15, 2023
f9e57ec
Merge branch 'main' into gitea-chart-update
TristanHoladay Dec 16, 2023
3ba7f4d
Merge branch 'main' into gitea-chart-update
Racer159 Dec 16, 2023
b8fdf4d
wip: minor refactors
TristanHoladay Dec 18, 2023
2cff54f
Merge branch 'main' into gitea-chart-update
TristanHoladay Dec 18, 2023
892f6a1
wip: updating gitea chart version to 10.0.0 -- updating gitea values …
TristanHoladay Dec 18, 2023
1fba065
wip: update e2e sbom test gitea version.
TristanHoladay Dec 18, 2023
7ce9de5
Merge branch 'main' into gitea-chart-update
Racer159 Dec 19, 2023
21a9c7d
wip: moved wait and added 422 check in CreateReadOnlyUser()
TristanHoladay Dec 19, 2023
ecf13b2
wip: removing else blocks in UpdateGiteaPVC() according GH Actions Va…
TristanHoladay Dec 19, 2023
6f24e90
wip: add statusCode to return of DoHTTPThings(); check statusCode in …
TristanHoladay Dec 19, 2023
ef009c5
fix linting issue
Racer159 Dec 19, 2023
07a6060
Update src/pkg/k8s/dynamic.go
Racer159 Dec 19, 2023
e754b54
Update zarf-config.toml
Racer159 Dec 19, 2023
0f8ec5a
Update src/test/e2e/06_create_sbom_test.go
Racer159 Dec 19, 2023
f838e10
Update src/test/e2e/06_create_sbom_test.go
Racer159 Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/gitea/gitea-values.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
persistence:
storageClass: "###ZARF_STORAGE_CLASS###"
existingClaim: "###ZARF_VAR_GIT_SERVER_EXISTING_PVC###"
claimName: "###ZARF_VAR_GIT_SERVER_EXISTING_PVC###"
size: "###ZARF_VAR_GIT_SERVER_PVC_SIZE###"
accessModes:
- "###ZARF_VAR_GIT_SERVER_PVC_ACCESS_MODE###"
create: ###ZARF_VAR_GIT_SERVER_CREATE_PVC###

replicaCount: "###ZARF_VAR_GIT_SERVER_REPLICA_COUNT###"
replicaCount: ###ZARF_VAR_GIT_SERVER_REPLICA_COUNT###

gitea:
admin:
Expand All @@ -29,6 +30,12 @@ gitea:
repository:
ENABLE_PUSH_CREATE_USER: true
FORCE_PRIVATE: true
session:
PROVIDER: memory
cache:
ADAPTER: memory
queue:
TYPE: level
resources:
requests:
cpu: "###ZARF_VAR_GIT_SERVER_CPU_REQ###"
Expand All @@ -37,13 +44,13 @@ resources:
cpu: "###ZARF_VAR_GIT_SERVER_CPU_LIMIT###"
memory: "###ZARF_VAR_GIT_SERVER_MEM_LIMIT###"

memcached:
enabled: false

postgresql:
enabled: false

image:
repository: "###ZARF_CONST_GITEA_IMAGE###"
tag: "###ZARF_CONST_GITEA_SERVER_VERSION###"
rootless: true

postgresql-ha:
enabled: false

redis-cluster:
enabled: false
11 changes: 9 additions & 2 deletions packages/gitea/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
variables:
- name: GIT_SERVER_EXISTING_PVC
description: "Optional: Use an existing PVC for the git server instead of creating a new one. If this is set, the GIT_SERVER_PVC_SIZE variable will be ignored."
default: ""
default: "data-zarf-gitea-0"

- name: GIT_SERVER_PVC_SIZE
description: The size of the persistent volume claim for the git server
Expand Down Expand Up @@ -61,12 +61,17 @@ components:
- name: gitea
releaseName: zarf-gitea
url: https://dl.gitea.io/charts
version: 8.3.0
version: 9.5.1
namespace: zarf
valuesFiles:
- gitea-values.yaml
actions:
onDeploy:
before:
- cmd: ./zarf internal update-gitea-pvc --no-progress
setVariables:
- name: GIT_SERVER_CREATE_PVC
mute: true
after:
- cmd: ./zarf internal create-read-only-gitea-user --no-progress
maxRetries: 3
Expand All @@ -82,3 +87,5 @@ components:
namespace: zarf
name: app=gitea
condition: Ready
TristanHoladay marked this conversation as resolved.
Show resolved Hide resolved
onFailure:
- cmd: ./zarf internal update-gitea-pvc --rollback --no-progress
23 changes: 23 additions & 0 deletions src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
"github.com/spf13/pflag"
)

var (
rollback bool
)

var internalCmd = &cobra.Command{
Use: "internal",
Hidden: true,
Expand Down Expand Up @@ -196,6 +200,22 @@ var createPackageRegistryToken = &cobra.Command{
},
}

var updateGiteaPVC = &cobra.Command{
Use: "update-gitea-pvc",
Short: lang.CmdInternalUpdateGiteaPVCShort,
Long: lang.CmdInternalUpdateGiteaPVCLong,
Run: func(cmd *cobra.Command, args []string) {

// There is a possibility that the pvc does not yet exist and Gitea helm chart should create it
helmShouldCreate, err := git.UpdateGiteaPVC(rollback)
if err != nil {
message.WarnErr(err, lang.CmdInternalUpdateGiteaPVCErr)
}

fmt.Print(helmShouldCreate)
},
}

var isValidHostname = &cobra.Command{
Use: "is-valid-hostname",
Short: lang.CmdInternalIsValidHostnameShort,
Expand Down Expand Up @@ -229,8 +249,11 @@ func init() {
internalCmd.AddCommand(genTypesSchemaCmd)
internalCmd.AddCommand(createReadOnlyGiteaUser)
internalCmd.AddCommand(createPackageRegistryToken)
internalCmd.AddCommand(updateGiteaPVC)
internalCmd.AddCommand(isValidHostname)
internalCmd.AddCommand(computeCrc32)

updateGiteaPVC.Flags().BoolVarP(&rollback, "rollback", "r", false, lang.CmdInternalFlagUpdateGiteaPVCRollback)
}

func addHiddenDummyFlag(cmd *cobra.Command, flagDummy string) {
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/tools/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ var updateCredsCmd = &cobra.Command{
}
}
if slices.Contains(args, message.GitKey) && newState.GitServer.InternalServer {
err = h.UpdateZarfGiteaValues()
g := git.New(newState.GitServer)
err = g.UpdateZarfGiteaUsers(oldState)
if err != nil {
// Warn if we couldn't actually update the git server (it might not be installed and we should try to continue)
message.Warnf(lang.CmdToolsUpdateCredsUnableUpdateGit, err.Error())
Expand Down
6 changes: 6 additions & 0 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA
"This is called internally by the supported Gitea package component."
CmdInternalArtifactRegistryGiteaTokenErr = "Unable to create an artifact registry token for the Gitea service."

CmdInternalUpdateGiteaPVCShort = "Updates an existing Gitea persistent volume claim"
CmdInternalUpdateGiteaPVCLong = "Updates an existing Gitea persistent volume claim by assessing if claim is a custom user provided claim or default." +
"This is called internally by the supported Gitea package component."
CmdInternalUpdateGiteaPVCErr = "Unable to update the existing Gitea persistent volume claim."
CmdInternalFlagUpdateGiteaPVCRollback = "Roll back previous Gitea persistent volume claim updates."

CmdInternalIsValidHostnameShort = "Checks if the current machine's hostname is RFC1123 compliant"
CmdInternalIsValidHostnameErr = "The hostname '%s' is not valid. Ensure the hostname meets RFC1123 requirements https://www.rfc-editor.org/rfc/rfc1123.html."

Expand Down
136 changes: 91 additions & 45 deletions src/internal/packager/git/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"encoding/json"
"fmt"
"io"
"os"
"time"

netHttp "net/http"
Expand All @@ -17,6 +18,8 @@
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/k8s"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/types"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// CreateTokenResponse is the response given from creating a token in Gitea
Expand Down Expand Up @@ -49,50 +52,6 @@

tunnelURL := tunnel.HTTPEndpoint()

var out []byte

// Determine if the read only user already exists
TristanHoladay marked this conversation as resolved.
Show resolved Hide resolved
getUserEndpoint := fmt.Sprintf("%s/api/v1/admin/users", tunnelURL)
getUserRequest, _ := netHttp.NewRequest("GET", getUserEndpoint, nil)
err = tunnel.Wrap(func() error {
out, err = g.DoHTTPThings(getUserRequest, g.Server.PushUsername, g.Server.PushPassword)
return err
})
message.Debugf("GET %s:\n%s", getUserEndpoint, string(out))
if err != nil {
return err
}

hasReadOnlyUser := false
var users []map[string]interface{}
err = json.Unmarshal(out, &users)
if err != nil {
return err
}

for _, user := range users {
if user["login"] == g.Server.PullUsername {
hasReadOnlyUser = true
}
}

if hasReadOnlyUser {
// Update the existing user's password
updateUserBody := map[string]interface{}{
"login_name": g.Server.PullUsername,
"password": g.Server.PullPassword,
}
updateUserData, _ := json.Marshal(updateUserBody)
updateUserEndpoint := fmt.Sprintf("%s/api/v1/admin/users/%s", tunnelURL, g.Server.PullUsername)
updateUserRequest, _ := netHttp.NewRequest("PATCH", updateUserEndpoint, bytes.NewBuffer(updateUserData))
err = tunnel.Wrap(func() error {
out, err = g.DoHTTPThings(updateUserRequest, g.Server.PushUsername, g.Server.PushPassword)
return err
})
message.Debugf("PATCH %s:\n%s", updateUserEndpoint, string(out))
return err
}

// Create json representation of the create-user request body
createUserBody := map[string]interface{}{
"username": g.Server.PullUsername,
Expand All @@ -105,6 +64,8 @@
return err
}

var out []byte

// Send API request to create the user
createUserEndpoint := fmt.Sprintf("%s/api/v1/admin/users", tunnelURL)
createUserRequest, _ := netHttp.NewRequest("POST", createUserEndpoint, bytes.NewBuffer(createUserData))
Expand Down Expand Up @@ -134,6 +95,61 @@
return err
}

// UpdateZarfGiteaUsers updates Zarf gitea users
func (g *Git) UpdateZarfGiteaUsers(oldState *types.ZarfState) error {

//Update git read only user password
err := g.UpdateGitUser(oldState.GitServer.PushPassword, g.Server.PullUsername, g.Server.PullPassword)
if err != nil {
return fmt.Errorf("unable to update gitea read only user password: %w", err)
}

// Update Git admin password
err = g.UpdateGitUser(oldState.GitServer.PushPassword, g.Server.PushUsername, g.Server.PushPassword)
if err != nil {
return fmt.Errorf("unable to update gitea admin user password: %w", err)
}
return nil
}

// UpdateGitUser updates Zarf git server users
func (g *Git) UpdateGitUser(oldAdminPass string, username string, userpass string) error {
message.Debugf("git.UpdateGitUser()")

c, err := cluster.NewCluster()
if err != nil {
return err
}
// Establish a git tunnel to send the repo
tunnel, err := c.NewTunnel(cluster.ZarfNamespaceName, k8s.SvcResource, cluster.ZarfGitServerName, "", 0, cluster.ZarfGitServerPort)
if err != nil {
return err
}
_, err = tunnel.Connect()
if err != nil {
return err
}
defer tunnel.Close()
tunnelURL := tunnel.HTTPEndpoint()

var out []byte

// Update the existing user's password
updateUserBody := map[string]interface{}{
"login_name": username,
"password": userpass,
}
updateUserData, _ := json.Marshal(updateUserBody)
updateUserEndpoint := fmt.Sprintf("%s/api/v1/admin/users/%s", tunnelURL, username)
updateUserRequest, _ := netHttp.NewRequest("PATCH", updateUserEndpoint, bytes.NewBuffer(updateUserData))
err = tunnel.Wrap(func() error {
out, err = g.DoHTTPThings(updateUserRequest, g.Server.PushUsername, oldAdminPass)
return err
})
message.Debugf("PATCH %s:\n%s", updateUserEndpoint, string(out))
return err
}

// CreatePackageRegistryToken uses the Gitea API to create a package registry token.
func (g *Git) CreatePackageRegistryToken() (CreateTokenResponse, error) {
message.Debugf("git.CreatePackageRegistryToken()")
Expand Down Expand Up @@ -199,7 +215,8 @@

createTokensEndpoint := fmt.Sprintf("http://%s/api/v1/users/%s/tokens", tunnelURL, g.Server.PushUsername)
createTokensBody := map[string]interface{}{
"name": config.ZarfArtifactTokenName,
"name": config.ZarfArtifactTokenName,
"scopes": []string{"read:user", "read:package", "write:package"},
}
createTokensData, _ := json.Marshal(createTokensBody)
createTokensRequest, _ := netHttp.NewRequest("POST", createTokensEndpoint, bytes.NewBuffer(createTokensData))
Expand All @@ -221,6 +238,35 @@
return createTokenResponse, nil
}

// UpdateGiteaPVC updates the existing Gitea persistent volume claim and tells Gitea whether to create or not.
func UpdateGiteaPVC(shouldRollBack bool) (string, error) {
c, err := cluster.NewCluster()
if err != nil {
return "false", err
}

pvcName := os.Getenv("ZARF_VAR_GIT_SERVER_EXISTING_PVC")
groupKind := schema.GroupKind{
Group: "",
Kind: "PersistentVolumeClaim",
}
labels := map[string]string{"app.kubernetes.io/managed-by": "Helm"}
annotations := map[string]string{"meta.helm.sh/release-name": "zarf-gitea", "meta.helm.sh/release-namespace": "zarf"}

if shouldRollBack {
err = c.K8s.RemoveLabelsAndAnnotations(cluster.ZarfNamespaceName, pvcName, groupKind, labels, annotations)
return "false", err
} else {

Check warning on line 259 in src/internal/packager/git/gitea.go

View workflow job for this annotation

GitHub Actions / validate

if block ends with a return statement, so drop this else and outdent its block
if pvcName == "data-zarf-gitea-0" {
err = c.K8s.AddLabelsAndAnnotations(cluster.ZarfNamespaceName, pvcName, groupKind, labels, annotations)
return "true", err
} else {

Check warning on line 263 in src/internal/packager/git/gitea.go

View workflow job for this annotation

GitHub Actions / validate

if block ends with a return statement, so drop this else and outdent its block
return "false", err
}
}

}

// DoHTTPThings adds http request boilerplate and perform the request, checking for a successful response.
func (g *Git) DoHTTPThings(request *netHttp.Request, username, secret string) ([]byte, error) {
message.Debugf("git.DoHttpThings()")
Expand Down
31 changes: 0 additions & 31 deletions src/internal/packager/helm/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package helm
import (
"fmt"

"github.com/defenseunicorns/zarf/src/internal/packager/git"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/k8s"
"github.com/defenseunicorns/zarf/src/pkg/message"
Expand Down Expand Up @@ -48,36 +47,6 @@ func (h *Helm) UpdateZarfRegistryValues() error {
return nil
}

// UpdateZarfGiteaValues updates the Zarf git server deployment with the new state values
func (h *Helm) UpdateZarfGiteaValues() error {
giteaValues := map[string]interface{}{
"gitea": map[string]interface{}{
"admin": map[string]interface{}{
"username": h.cfg.State.GitServer.PushUsername,
"password": h.cfg.State.GitServer.PushPassword,
},
},
}

h.chart = types.ZarfChart{
Namespace: "zarf",
ReleaseName: "zarf-gitea",
}

err := h.UpdateReleaseValues(giteaValues)
if err != nil {
return fmt.Errorf("error updating the release values: %w", err)
}

g := git.New(h.cfg.State.GitServer)
err = g.CreateReadOnlyUser()
if err != nil {
return fmt.Errorf("unable to create the new Gitea read only user: %w", err)
}

return nil
}

// UpdateZarfAgentValues updates the Zarf agent deployment with the new state values
func (h *Helm) UpdateZarfAgentValues() error {
spinner := message.NewProgressSpinner("Gathering information to update Zarf Agent TLS")
Expand Down
Loading
Loading