Skip to content

Commit

Permalink
remove add subdomain logic from update app (#3926)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Nov 3, 2023
1 parent 8a9ae39 commit b3b43c3
Showing 1 changed file with 10 additions and 63 deletions.
73 changes: 10 additions & 63 deletions api/server/handlers/porter_app/update_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
"github.com/porter-dev/porter/api/server/shared/apierrors"
"github.com/porter-dev/porter/api/server/shared/config"
"github.com/porter-dev/porter/api/types"
"github.com/porter-dev/porter/internal/deployment_target"
"github.com/porter-dev/porter/internal/models"
"github.com/porter-dev/porter/internal/porter_app"
v2 "github.com/porter-dev/porter/internal/porter_app/v2"
"github.com/porter-dev/porter/internal/telemetry"
)

Expand Down Expand Up @@ -101,6 +99,15 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
deploymentTargetID := request.DeploymentTargetId

telemetry.WithAttributes(span,
telemetry.AttributeKV{Key: "name", Value: request.Name},
telemetry.AttributeKV{Key: "deployment-target-id", Value: deploymentTargetID},
telemetry.AttributeKV{Key: "app-revision-id", Value: request.AppRevisionID},
telemetry.AttributeKV{Key: "commit-sha", Value: request.CommitSHA},
telemetry.AttributeKV{Key: "porter-yaml-path", Value: request.PorterYAMLPath},
telemetry.AttributeKV{Key: "is-env-override", Value: request.IsEnvOverride},
)

var overrides *porterv1.PorterApp
appProto := &porterv1.PorterApp{}

Expand Down Expand Up @@ -178,66 +185,6 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

var appRevisionID string
if request.AppRevisionID != "" {
appRevisionID = request.AppRevisionID
telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "app-revision-id", Value: request.AppRevisionID})
} else {
// set the internal porter domain if needed and this is the first update on a revision
app, err := v2.AppFromProto(appProto)
if err != nil {
err := telemetry.Error(ctx, span, err, "error converting app proto to app")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}

telemetry.WithAttributes(span,
telemetry.AttributeKV{Key: "app-name", Value: appProto.Name},
telemetry.AttributeKV{Key: "deployment-target-id", Value: request.DeploymentTargetId},
)

deploymentTargetDetails, err := deployment_target.DeploymentTargetDetails(ctx, deployment_target.DeploymentTargetDetailsInput{
ProjectID: int64(project.ID),
ClusterID: int64(cluster.ID),
DeploymentTargetID: deploymentTargetID,
CCPClient: c.Config().ClusterControlPlaneClient,
})
if err != nil {
err := telemetry.Error(ctx, span, err, "error getting deployment target details")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}

agent, err := c.GetAgent(r, cluster, "")
if err != nil {
err := telemetry.Error(ctx, span, err, "error getting kubernetes agent")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}

subdomainCreateInput := porter_app.CreatePorterSubdomainInput{
AppName: app.Name,
RootDomain: c.Config().ServerConf.AppRootDomain,
DNSClient: c.Config().DNSClient,
DNSRecordRepository: c.Repo().DNSRecord(),
KubernetesAgent: agent,
}

appWithDomains, err := addPorterSubdomainsIfNecessary(ctx, app, deploymentTargetDetails, subdomainCreateInput)
if err != nil {
err := telemetry.Error(ctx, span, err, "error adding porter subdomains")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
return
}

appProto, _, err = v2.ProtoFromApp(ctx, appWithDomains)
if err != nil {
err := telemetry.Error(ctx, span, err, "error converting app to proto")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}
}

var serviceDeletions map[string]*porterv1.ServiceDeletions
if request.Deletions.ServiceDeletions != nil {
serviceDeletions = make(map[string]*porterv1.ServiceDeletions)
Expand All @@ -255,7 +202,7 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Id: deploymentTargetID,
},
App: appProto,
AppRevisionId: appRevisionID,
AppRevisionId: request.AppRevisionID,
AppEnv: &porterv1.EnvGroupVariables{
Normal: envVariables,
Secret: request.Secrets,
Expand Down

0 comments on commit b3b43c3

Please sign in to comment.