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

Followup - prevent handleRepositories from crashing | Stop using pointers in logs | Fix fetching service from repo #262

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Bugfix-20240221-191652.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Bugfix
body: Fix bug where service repos were never renamed if base dir was /
time: 2024-02-21T19:16:52.351803-05:00
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ src/dist
**/coverage.txt
**/go.work*
**/opslevel-k8s.yaml
**/kubectl-opslevel
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ service:
# find annotations with format: opslevel.com/tools.<category>.<displayname>: <url>
- '.metadata.annotations | to_entries | map(select(.key | startswith("opslevel.com/tools"))) | map({"category": .key | split(".")[2], "displayName": .key | split(".")[3], "url": .value})'
repositories: # attach repositories to the service using the opslevel repo alias - IE github.com:hashicorp/vault
- '{"name": "My Cool Repo", "directory": "/", "repo": .metadata.annotations.repo} | if .repo then . else empty end'
- '{"name": "My Cool Repo", "directory": "", "repo": .metadata.annotations.repo} | if .repo then . else empty end'
# if just the alias is returned as a single string we'll build the name for you and set the directory to "/"
- .metadata.annotations.repo
# find annotations with format: opslevel.com/repo.<displayname>.<repo.subpath.dots.turned.to.forwardslash>: <opslevel repo alias>
Expand Down
2 changes: 1 addition & 1 deletion src/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ service:
# OR find annotations with format: opslevel.com/tools.<category>.<environment>.<displayname>: <url>
# - '.metadata.annotations | to_entries | map(select(.key | startswith("opslevel.com/tools"))) | map({"category": .key | split(".")[2], "environment": .key | split(".")[3], "displayName": .key | split(".")[4], "url": .value})'
repositories: # attach repositories to the service using the opslevel repo alias - IE github.com:hashicorp/vault
- '{"name": "My Cool Repo", "directory": "/", "repo": .metadata.annotations.repo} | if .repo then . else empty end'
- '{"name": "My Cool Repo", "directory": "", "repo": .metadata.annotations.repo} | if .repo then . else empty end'
# if just the alias is returned as a single string we'll build the name for you and set the directory to "/"
- .metadata.annotations.repo
# find annotations with format: opslevel.com/repo.<displayname>.<repo.subpath.dots.turned.to.forwardslash>: <opslevel repo alias>
Expand Down
29 changes: 20 additions & 9 deletions src/common/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,26 @@ func (r *ServiceReconciler) handleTools(service *opslevel.Service, registration

func (r *ServiceReconciler) handleRepositories(service *opslevel.Service, registration opslevel_jq_parser.ServiceRegistration) {
for _, repositoryCreate := range registration.Repositories {
if repositoryCreate.Repository.Alias == nil || *repositoryCreate.Repository.Alias == "null" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#36

Checking for string "null" because of this^

continue
}
repoCreateString := "repoCreate{}"
b, err := json.Marshal(repositoryCreate)
if err == nil {
repoCreateString = string(b)
}
foundRepository, foundRepositoryErr := r.client.GetRepositoryWithAlias(*repositoryCreate.Repository.Alias)
if foundRepositoryErr != nil {
log.Warn().Msgf("[%s] Repository with alias: '%+v' not found so it cannot be attached to service ... skipping", service.Name, repositoryCreate)
log.Warn().Msgf("[%s] Repository with alias: '%s' not found so it cannot be attached to service ... skipping", service.Name, repoCreateString)
continue
} else if foundRepository == nil {
log.Warn().Msgf("[%s] Repository with alias: '%+v' call to GetRepositoryWithAlias unexpectedly returned nil - please submit a bug report ... skipping", service.Name, repositoryCreate)
log.Warn().Msgf("[%s] Repository with alias: '%s' call to GetRepositoryWithAlias unexpectedly returned nil - please submit a bug report ... skipping", service.Name, repoCreateString)
continue
}
serviceRepository := foundRepository.GetService(service.Id, *repositoryCreate.BaseDirectory)
var serviceRepository *opslevel.ServiceRepository
if repositoryCreate.BaseDirectory != nil {
serviceRepository = foundRepository.GetService(service.Id, *repositoryCreate.BaseDirectory)
}
if serviceRepository != nil {
if repositoryCreate.DisplayName != nil && serviceRepository.DisplayName != *repositoryCreate.DisplayName {
repositoryUpdate := opslevel.ServiceRepositoryUpdateInput{
Expand All @@ -380,22 +391,22 @@ func (r *ServiceReconciler) handleRepositories(service *opslevel.Service, regist
}
err := r.client.UpdateServiceRepository(repositoryUpdate)
if err != nil {
log.Error().Msgf("[%s] Failed updating repository '%+v'\n\tREASON: %v", service.Name, repositoryCreate, err.Error())
log.Error().Msgf("[%s] Failed updating repository '%s'\n\tREASON: %v", service.Name, repoCreateString, err.Error())
continue
} else {
log.Info().Msgf("[%s] Updated repository '%+v'", service.Name, repositoryCreate)
log.Info().Msgf("[%s] Updated repository '%s'", service.Name, repoCreateString)
continue
}
}
log.Debug().Msgf("[%s] Repository '%+v' already attached to service ... skipping", service.Name, repositoryCreate)
log.Debug().Msgf("[%s] Repository '%s' already attached to service ... skipping", service.Name, repoCreateString)
continue
}
repositoryCreate.Service = opslevel.IdentifierInput{Id: &service.Id}
err := r.client.CreateServiceRepository(repositoryCreate)
err = r.client.CreateServiceRepository(repositoryCreate)
if err != nil {
log.Error().Msgf("[%s] Failed assigning repository '%+v'\n\tREASON: %v", service.Name, repositoryCreate, err.Error())
log.Error().Msgf("[%s] Failed assigning repository '%s'\n\tREASON: %v", service.Name, repoCreateString, err.Error())
} else {
log.Info().Msgf("[%s] Attached repository '%+v'", service.Name, repositoryCreate)
log.Info().Msgf("[%s] Attached repository '%s'", service.Name, repoCreateString)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ require (
k8s.io/apimachinery v0.29.2 // indirect
k8s.io/client-go v0.29.2 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240220201932-37d671a357a5 // indirect
k8s.io/kube-openapi v0.0.0-20240221221325-2ac9dc51f3f1 // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
nhooyr.io/websocket v1.8.10 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
4 changes: 2 additions & 2 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ k8s.io/client-go v0.29.2 h1:FEg85el1TeZp+/vYJM7hkDlSTFZ+c5nnK44DJ4FyoRg=
k8s.io/client-go v0.29.2/go.mod h1:knlvFZE58VpqbQpJNbCbctTVXcd35mMyAAwBdpt4jrA=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240220201932-37d671a357a5 h1:QSpdNrZ9uRlV0VkqLvVO0Rqg8ioKi3oSw7O5P7pJV8M=
k8s.io/kube-openapi v0.0.0-20240220201932-37d671a357a5/go.mod h1:Pa1PvrP7ACSkuX6I7KYomY6cmMA0Tx86waBhDUgoKPw=
k8s.io/kube-openapi v0.0.0-20240221221325-2ac9dc51f3f1 h1:rtdnaWfP40MTKv7izH81gkWpZB45pZrwIxyZdPSn1mI=
k8s.io/kube-openapi v0.0.0-20240221221325-2ac9dc51f3f1/go.mod h1:Pa1PvrP7ACSkuX6I7KYomY6cmMA0Tx86waBhDUgoKPw=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
Expand Down
Loading