Skip to content

Commit

Permalink
[deckhouse-controller] Fix auth data handling in change-registry helper
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Vasilenko <maksim.vasilenko@flant.com>
  • Loading branch information
Maxim Vasilenko committed Jan 10, 2024
1 parent d991192 commit 4db6f9e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/ci_templates/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{!{ define "unit_run_args" }!}
# <template: unit_run_args>
args: 'make tests-modules'
args: 'make tests-modules tests-controller'
docker_options: '-w /deckhouse -v ${{github.workspace}}:/deckhouse -e "TERM=xterm-256color" -v ~/go-pkg-cache:/go/pkg'
# <template: unit_run_args>
{!{- end -}!}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ jobs:
echo "⚓️ 📥 [$(date -u)] Pull 'tests' image..."
docker pull ${TESTS_IMAGE_NAME}
echo "⚓️ 🏎 [$(date -u)] Run tests..."
docker run -w /deckhouse -v ${{github.workspace}}:/deckhouse -e "TERM=xterm-256color" -v ~/go-pkg-cache:/go/pkg ${TESTS_IMAGE_NAME} make tests-modules
docker run -w /deckhouse -v ${{github.workspace}}:/deckhouse -e "TERM=xterm-256color" -v ~/go-pkg-cache:/go/pkg ${TESTS_IMAGE_NAME} make tests-modules tests-controller
# </template: tests_before_build_template>

matrix_tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test_pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ jobs:
echo "⚓️ 📥 [$(date -u)] Pull 'tests' image..."
docker pull ${TESTS_IMAGE_NAME}
echo "⚓️ 🏎 [$(date -u)] Run tests..."
docker run -w /deckhouse -v ${{github.workspace}}:/deckhouse -e "TERM=xterm-256color" -v ~/go-pkg-cache:/go/pkg ${TESTS_IMAGE_NAME} make tests-modules
docker run -w /deckhouse -v ${{github.workspace}}:/deckhouse -e "TERM=xterm-256color" -v ~/go-pkg-cache:/go/pkg ${TESTS_IMAGE_NAME} make tests-modules tests-controller
# </template: tests_before_build_template>

matrix_tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ jobs:
echo "⚓️ 📥 [$(date -u)] Pull 'tests' image..."
docker pull ${TESTS_IMAGE_NAME}
echo "⚓️ 🏎 [$(date -u)] Run tests..."
docker run -w /deckhouse -v ${{github.workspace}}:/deckhouse -e "TERM=xterm-256color" -v ~/go-pkg-cache:/go/pkg ${TESTS_IMAGE_NAME} make tests-modules
docker run -w /deckhouse -v ${{github.workspace}}:/deckhouse -e "TERM=xterm-256color" -v ~/go-pkg-cache:/go/pkg ${TESTS_IMAGE_NAME} make tests-modules tests-controller
# </template: tests_before_build_template>
# <template: update_comment_on_finish>
- name: Update comment on finish
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bin/gator: bin/gator-${GATOR_VERSION}/gator
rm -f bin/gator
ln -s /deckhouse/bin/gator-${GATOR_VERSION}/gator bin/gator

.PHONY: tests-modules tests-matrix tests-openapi tests-prometheus
.PHONY: tests-modules tests-matrix tests-openapi tests-prometheus tests-controller
tests-modules: ## Run unit tests for modules hooks and templates.
##~ Options: FOCUS=module-name
go test -timeout=${TESTS_TIMEOUT} -vet=off ${TESTS_PATH}
Expand All @@ -136,6 +136,9 @@ tests-matrix: bin/promtool bin/gator ## Test how helm templates are rendered wit
tests-openapi: ## Run tests against modules openapi values schemas.
go test -vet=off ./testing/openapi_cases/

tests-controller: ## Run deckhouse-controller unit tests.
go test ./deckhouse-controller/... -v

.PHONY: tests-doc-links
tests-doc-links: ## Build documentation and run checker of html links.
bash tools/doc_check_links.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,15 @@ func updateImagePullSecret(ctx context.Context, kubeCl *kclient.KubernetesClient
}

func newImagePullSecretData(newRepo name.Repository, authConfig authn.AuthConfig, caContent string) (map[string]string, error) {
var authCfg authn.AuthConfig
if authConfig.Username != "" && authConfig.Password != "" {
authCfg.Auth = base64.StdEncoding.EncodeToString([]byte(authConfig.Username + ":" + authConfig.Password))
}
// var authCfg authn.AuthConfig
// if authConfig.Username != "" && authConfig.Password != "" {
// authCfg.Auth = base64.StdEncoding.EncodeToString([]byte(authConfig.Username + ":" + authConfig.Password))
// }

authConfBytes, err := json.Marshal(
map[string]map[string]authn.AuthConfig{
map[string]map[string]*dockerCfgAuthEntry{
"auths": {
newRepo.RegistryStr(): authCfg,
newRepo.RegistryStr(): encodeDockerCfgAuthEntryFromAuthConfig(authConfig),
},
},
)
Expand Down Expand Up @@ -412,3 +413,15 @@ func authHeaderWithBearer(header http.Header) bool {

return strings.ToLower(header.Get(wwwAuthHeader)) == bearer
}

type dockerCfgAuthEntry struct {
Auth string `json:"auth,omitempty"`
}

func encodeDockerCfgAuthEntryFromAuthConfig(authConfig authn.AuthConfig) *dockerCfgAuthEntry {
if authConfig.Username == "" && authConfig.Password == "" {
return &dockerCfgAuthEntry{}
}

return &dockerCfgAuthEntry{Auth: base64.StdEncoding.EncodeToString([]byte(authConfig.Username + ":" + authConfig.Password))}
}

0 comments on commit 4db6f9e

Please sign in to comment.