Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nmaas Janitor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nmaas
nmaas Janitor
Commits
dd2d662f
Commit
dd2d662f
authored
1 year ago
by
Łukasz Łopatowski
Browse files
Options
Downloads
Patches
Plain Diff
Simplified loading single GitLab project data by name
parent
98761182
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/service/v1/config-service.go
+9
-22
9 additions, 22 deletions
pkg/service/v1/config-service.go
with
9 additions
and
22 deletions
pkg/service/v1/config-service.go
+
9
−
22
View file @
dd2d662f
...
...
@@ -145,23 +145,13 @@ func (s *configServiceServer) FindGitlabProjectId(api *gitlab.Client, uid string
return
-
1
,
status
.
Errorf
(
codes
.
NotFound
,
"Gitlab Group for given domain does not exist"
)
}
//List group projects
logLine
(
fmt
.
Sprintf
(
"Searching for GitLab Projects within Group %d / %s"
,
groups
[
0
]
.
ID
,
groups
[
0
]
.
Name
))
projs
,
_
,
err
:=
api
.
Groups
.
ListGroupProjects
(
groups
[
0
]
.
ID
,
nil
)
if
err
!=
nil
||
len
(
projs
)
==
0
{
logLine
(
fmt
.
Sprintf
(
"Group %s is empty or inaccessible"
,
groups
[
0
]
.
Name
))
return
-
1
,
status
.
Errorf
(
codes
.
NotFound
,
"Project containing config not found on Gitlab"
)
}
//Find our project in group projects list
logLine
(
fmt
.
Sprintf
(
"Found %d projects and looking for %s"
,
len
(
projs
),
uid
))
for
_
,
proj
:=
range
projs
{
if
proj
.
Name
==
uid
{
return
proj
.
ID
,
nil
}
}
project
,
_
,
err
:=
api
.
Projects
.
GetProject
(
uid
,
&
gitlab
.
GetProjectOptions
{})
if
err
!=
nil
{
log
.
Print
(
err
)
return
-
1
,
status
.
Errorf
(
codes
.
NotFound
,
"Gitlab Project for given uid does not exist"
)
}
return
-
1
,
status
.
Errorf
(
codes
.
NotFound
,
"Project containing config not found on Gitlab"
)
return
project
.
ID
,
nil
}
//Parse repository files into string:string map for configmap creator
...
...
@@ -257,7 +247,7 @@ func (s *configServiceServer) CreateOrReplace(ctx context.Context, req *v1.Insta
proj
,
err
:=
s
.
FindGitlabProjectId
(
s
.
gitAPI
,
depl
.
Uid
,
depl
.
Domain
)
if
err
!=
nil
{
return
prepareResponse
(
v1
.
Status_FAILED
,
"Cannot find corresponding
g
it
lab assets
"
),
err
return
prepareResponse
(
v1
.
Status_FAILED
,
"Cannot find corresponding
G
it
Lap project
"
),
err
}
//check if given k8s namespace exists
...
...
@@ -294,22 +284,19 @@ func (s *configServiceServer) CreateOrReplace(ctx context.Context, req *v1.Insta
_
,
err
=
s
.
kubeAPI
.
CoreV1
()
.
ConfigMaps
(
depl
.
Namespace
)
.
Get
(
ctx
,
cm
.
Name
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
//Not exists, we create new
_
,
err
=
s
.
kubeAPI
.
CoreV1
()
.
ConfigMaps
(
depl
.
Namespace
)
.
Create
(
ctx
,
&
cm
,
metav1
.
CreateOptions
{})
if
err
!=
nil
{
return
prepareResponse
(
v1
.
Status_FAILED
,
"Failed to create ConfigMap"
),
err
}
}
else
{
//Already exists, we update it
_
,
err
=
s
.
kubeAPI
.
CoreV1
()
.
ConfigMaps
(
depl
.
Namespace
)
.
Update
(
ctx
,
&
cm
,
metav1
.
UpdateOptions
{})
if
err
!=
nil
{
return
prepareResponse
(
v1
.
Status_FAILED
,
"Error while updating
c
onfig
m
ap!"
),
err
return
prepareResponse
(
v1
.
Status_FAILED
,
"Error while updating
existing C
onfig
M
ap!"
),
err
}
}
}
return
prepareResponse
(
v1
.
Status_OK
,
"ConfigMap created successfully"
),
nil
return
prepareResponse
(
v1
.
Status_OK
,
"ConfigMap created
/updated
successfully"
),
nil
}
//Delete all config maps for instance
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment