Skip to content

Commit

Permalink
[patch] Remove namespace name from release name (#131)
Browse files Browse the repository at this point in the history
* remove namesapce name from release name

* fis test
  • Loading branch information
sunny299 authored Apr 29, 2022
1 parent fa939bf commit 0f5bfaa
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 18 deletions.
9 changes: 4 additions & 5 deletions internal/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ const (
)

// GenReleaseName returns the release name for deploying components
func GenReleaseName(namespace, compName string) string {
refName := namespace + "-" + compName
if len(refName) > MaxReleaseNameLength {
func GenReleaseName(compName string) string {
if len(compName) > MaxReleaseNameLength {
// component name is more important than team name
return refName[len(refName)-MaxReleaseNameLength:]
return compName[len(compName)-MaxReleaseNameLength:]
}
return refName
return compName
}
2 changes: 1 addition & 1 deletion internal/samsahai/activepromotion/environment_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *controller) deleteAllComponentsInNamespace(teamName, ns string, started
}

for compName := range parentComps {
refName := internal.GenReleaseName(ns, compName)
refName := internal.GenReleaseName(compName)
if err := deployEngine.Delete(refName); err != nil {
logger.Error(err, "cannot delete release",
"refName", refName,
Expand Down
2 changes: 1 addition & 1 deletion internal/samsahai/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ func (c *controller) DeleteTeamActiveEnvironment(teamName, namespace, deletedBy
}

for compName := range parentComps {
refName := internal.GenReleaseName(namespace, compName)
refName := internal.GenReleaseName(compName)
if err := deployEngine.Delete(refName); err != nil &&
!k8serrors.IsNotFound(err) {
logger.Error(err, "cannot delete release",
Expand Down
5 changes: 1 addition & 4 deletions internal/samsahai/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,7 @@ func (c *controller) getDifferentServices(prSvcList, activeSvcList *corev1.Servi
}

func (c *controller) replaceServiceFromReleaseName(svcName, prNamespace, activeNamespace string) string {
prReleaseName := s2h.GenReleaseName(prNamespace, "")
activeReleaseName := s2h.GenReleaseName(activeNamespace, "")

return strings.ReplaceAll(svcName, activeReleaseName, prReleaseName)
return strings.ReplaceAll(svcName, activeNamespace, prNamespace)
}

func (c *controller) ensureTeamPullRequestNamespaceUpdated(teamName, targetNs string) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/staging/collect_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (c *controller) setDeploymentIssues(queue *s2hv1.Queue) error {
deploymentIssuesMaps := make(map[s2hv1.DeploymentIssueType][]s2hv1.FailureComponent)
for parentComp := range parentComps {
ns := c.namespace
refName := internal.GenReleaseName(ns, parentComp)
refName := internal.GenReleaseName(parentComp)
selectors := deployEngine.GetLabelSelectors(refName)
if len(selectors) == 0 {
continue
Expand Down
6 changes: 3 additions & 3 deletions internal/staging/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (c *controller) cleanBefore(queue *s2hv1.Queue) error {

if !queue.Status.IsConditionTrue(s2hv1.QueueCleanedBefore) {
for compName := range parentComps {
refName := internal.GenReleaseName(c.namespace, compName)
refName := internal.GenReleaseName(compName)
if err := deployEngine.Delete(refName); err != nil {
logger.Error(err, "cannot delete release",
"refName", refName,
Expand Down Expand Up @@ -402,7 +402,7 @@ func (c *controller) cleanAfter(queue *s2hv1.Queue) error {

if !queue.Status.IsConditionTrue(s2hv1.QueueCleanedAfter) {
for compName := range parentComps {
refName := internal.GenReleaseName(c.namespace, compName)
refName := internal.GenReleaseName(compName)
if err := deployEngine.Delete(refName); err != nil {
logger.Error(err, "cannot delete release",
"refName", refName,
Expand Down Expand Up @@ -475,7 +475,7 @@ func WaitForComponentsCleaned(
}

for compName := range parentComps {
refName := internal.GenReleaseName(namespace, compName)
refName := internal.GenReleaseName(compName)
selectors := deployEngine.GetLabelSelectors(refName)
listOpt := &client.ListOptions{Namespace: namespace, LabelSelector: labels.SelectorFromSet(selectors)}
log := logger.WithValues(
Expand Down
2 changes: 1 addition & 1 deletion internal/staging/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (c *controller) updateQueueWithState(q *s2hv1.Queue, state s2hv1.QueueState
}

func (c *controller) genReleaseName(comp *s2hv1.Component) string {
return internal.GenReleaseName(c.namespace, comp.Name)
return internal.GenReleaseName(comp.Name)
}

func (c *controller) updateQueueHistory(q *s2hv1.Queue) error {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/staging/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = Describe("[e2e] Staging controller", func() {
}

nginxReplicas := int32(1)
nginxLabels := map[string]string{"app": "nginx", "release": "samsahai-system-redis"}
nginxLabels := map[string]string{"app": "nginx", "release": "redis"}
deployNginx := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "nginx",
Expand Down Expand Up @@ -561,7 +561,7 @@ var _ = Describe("[e2e] Staging controller", func() {
Expect(client.Update(ctx, &config)).To(BeNil())

By("Ensure Pre Active Components")
redisServiceName := fmt.Sprintf("%s-redis-master", namespace)
redisServiceName := fmt.Sprintf("%s-master", redisCompName)

err = wait.PollImmediate(2*time.Second, deployTimeout, func() (ok bool, err error) {
queue, err := queue.EnsurePreActiveComponents(client, teamName, namespace, true)
Expand Down

0 comments on commit 0f5bfaa

Please sign in to comment.