Ian Edwards 2 лет назад
Родитель
Сommit
737ead1de5

+ 0 - 48
api/client/porter_app.go

@@ -6,7 +6,6 @@ import (
 
 	"github.com/porter-dev/porter/api/server/handlers/porter_app"
 	"github.com/porter-dev/porter/internal/models"
-	appInternal "github.com/porter-dev/porter/internal/porter_app"
 
 	"github.com/porter-dev/porter/api/types"
 )
@@ -316,53 +315,6 @@ type CreatePorterAppDBEntryInput struct {
 	DeploymentTargetID string
 }
 
-// CreatePorterAppDBEntry creates an entry in the porter app
-func (c *Client) CreatePorterAppDBEntry(
-	ctx context.Context,
-	projectID uint, clusterID uint,
-	inp CreatePorterAppDBEntryInput,
-) error {
-	var sourceType appInternal.SourceType
-	var image *appInternal.Image
-	if inp.Local {
-		sourceType = appInternal.SourceType_Local
-	}
-	if inp.GitRepoName != "" {
-		sourceType = appInternal.SourceType_Github
-	}
-	if inp.ImageRepository != "" {
-		sourceType = appInternal.SourceType_DockerRegistry
-		image = &appInternal.Image{
-			Repository: inp.ImageRepository,
-			Tag:        inp.ImageTag,
-		}
-	}
-
-	req := &porter_app.CreateAppRequest{
-		Name:       inp.AppName,
-		SourceType: sourceType,
-		GitSource: porter_app.GitSource{
-			GitBranch:   inp.GitBranch,
-			GitRepoName: inp.GitRepoName,
-			GitRepoID:   inp.GitRepoID,
-		},
-		Image:              image,
-		PorterYamlPath:     inp.PorterYamlPath,
-		DeploymentTargetID: inp.DeploymentTargetID,
-	}
-
-	err := c.postRequest(
-		fmt.Sprintf(
-			"/projects/%d/clusters/%d/apps/create",
-			projectID, clusterID,
-		),
-		req,
-		&types.PorterApp{},
-	)
-
-	return err
-}
-
 // CreateSubdomain returns a subdomain for a given service that point to the ingress-nginx service in the cluster
 func (c *Client) CreateSubdomain(
 	ctx context.Context,

+ 0 - 167
api/server/handlers/porter_app/create_app.go

@@ -1,167 +0,0 @@
-package porter_app
-
-import (
-	"errors"
-	"net/http"
-
-	"connectrpc.com/connect"
-
-	porterv1 "github.com/porter-dev/api-contracts/generated/go/porter/v1"
-
-	"github.com/porter-dev/porter/api/server/handlers"
-	"github.com/porter-dev/porter/api/server/shared"
-	"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/models"
-	"github.com/porter-dev/porter/internal/porter_app"
-	"github.com/porter-dev/porter/internal/repository"
-	"github.com/porter-dev/porter/internal/telemetry"
-)
-
-// ErrMissingSourceType is returned when the source type is not specified
-var ErrMissingSourceType = errors.New("missing source type")
-
-// CreateAppHandler is the handler for the /apps/create endpoint
-type CreateAppHandler struct {
-	handlers.PorterHandlerReadWriter
-}
-
-// NewCreateAppHandler handles POST requests to the endpoint /apps/create
-func NewCreateAppHandler(
-	config *config.Config,
-	decoderValidator shared.RequestDecoderValidator,
-	writer shared.ResultWriter,
-) *CreateAppHandler {
-	return &CreateAppHandler{
-		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
-	}
-}
-
-// GitSource is the github metadata for an app
-type GitSource struct {
-	GitBranch   string `json:"git_branch"`
-	GitRepoName string `json:"git_repo_name"`
-	GitRepoID   uint   `json:"git_repo_id"`
-}
-
-// CreateAppRequest is the request object for the /apps/create endpoint
-type CreateAppRequest struct {
-	GitSource            `json:",inline"`
-	SourceType           porter_app.SourceType `json:"type"`
-	PorterYamlPath       string                `json:"porter_yaml_path"`
-	Image                *porter_app.Image     `json:"image,omitempty"`
-	Name                 string                `json:"name"`
-	DeploymentTargetName string                `json:"deployment_target_name,omitempty"`
-	DeploymentTargetID   string                `json:"deployment_target_id,omitempty"`
-}
-
-// CreateGithubAppInput is the input for creating an app with a github source
-type CreateGithubAppInput struct {
-	ProjectID           uint
-	ClusterID           uint
-	Name                string
-	GitBranch           string
-	GitRepoName         string
-	PorterYamlPath      string
-	GitRepoID           uint
-	PorterAppRepository repository.PorterAppRepository
-}
-
-// CreateDockerRegistryAppInput is the input for creating an app with a docker registry source
-type CreateDockerRegistryAppInput struct {
-	ProjectID           uint
-	ClusterID           uint
-	Name                string
-	Repository          string
-	Tag                 string
-	PorterAppRepository repository.PorterAppRepository
-}
-
-// CreateLocalAppInput is the input for creating an app that is built locally via the cli
-type CreateLocalAppInput struct {
-	ProjectID           uint
-	ClusterID           uint
-	Name                string
-	PorterAppRepository repository.PorterAppRepository
-}
-
-func (c *CreateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	ctx, span := telemetry.NewSpan(r.Context(), "serve-create-app")
-	defer span.End()
-
-	project, _ := ctx.Value(types.ProjectScope).(*models.Project)
-	cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)
-
-	if !project.GetFeatureFlag(models.ValidateApplyV2, c.Config().LaunchDarklyClient) {
-		err := telemetry.Error(ctx, span, nil, "project does not have validate apply v2 enabled")
-		c.HandleAPIError(w, r, apierrors.NewErrForbidden(err))
-		return
-	}
-
-	request := &CreateAppRequest{}
-	if ok := c.DecodeAndValidate(w, r, request); !ok {
-		err := telemetry.Error(ctx, span, nil, "error decoding request")
-		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
-		return
-	}
-
-	if request.Name == "" {
-		err := telemetry.Error(ctx, span, nil, "name is required")
-		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
-		return
-	}
-	telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "app-name", Value: request.Name})
-
-	porterApp, err := porter_app.CreateOrGetAppRecord(ctx, porter_app.CreateOrGetAppRecordInput{
-		ClusterID:           cluster.ID,
-		ProjectID:           project.ID,
-		Name:                request.Name,
-		SourceType:          request.SourceType,
-		GitBranch:           request.GitBranch,
-		GitRepoName:         request.GitRepoName,
-		GitRepoID:           request.GitRepoID,
-		PorterYamlPath:      request.PorterYamlPath,
-		Image:               request.Image,
-		PorterAppRepository: c.Repo().PorterApp(),
-	})
-	if err != nil {
-		err := telemetry.Error(ctx, span, err, "error creating porter app")
-		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
-		return
-	}
-
-	telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "app-id", Value: porterApp.ID})
-
-	telemetry.WithAttributes(span,
-		telemetry.AttributeKV{Key: "deployment-target-name", Value: request.DeploymentTargetName},
-		telemetry.AttributeKV{Key: "deployment-target-id", Value: request.DeploymentTargetID},
-	)
-
-	if request.DeploymentTargetName != "" || request.DeploymentTargetID != "" {
-		createAppInstanceReq := connect.NewRequest(&porterv1.CreateAppInstanceRequest{
-			ProjectId: int64(project.ID),
-			AppName:   request.Name,
-			DeploymentTargetIdentifier: &porterv1.DeploymentTargetIdentifier{
-				Id:   request.DeploymentTargetID,
-				Name: request.DeploymentTargetName,
-			},
-			PorterAppId: int64(porterApp.ID),
-		})
-
-		createAppInstanceResp, err := c.Config().ClusterControlPlaneClient.CreateAppInstance(ctx, createAppInstanceReq)
-		if err != nil {
-			// ignore error until app instances are fully supported: POR-2056
-			telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "create-app-instance-error", Value: err.Error()})
-		}
-
-		if createAppInstanceResp == nil || createAppInstanceResp.Msg == nil {
-			// ignore error until app instances are fully supported: POR-2056
-			telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "create-app-instance-nil", Value: true})
-		} else {
-			telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "app-instance-id", Value: createAppInstanceResp.Msg.AppInstanceId})
-		}
-	}
-
-	c.WriteResult(w, r, porterApp)
-}

+ 7 - 0
api/server/handlers/porter_app/update_app.go

@@ -321,6 +321,13 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	c.WriteResult(w, r, response)
 }
 
+// GitSource is the github metadata for an app
+type GitSource struct {
+	GitBranch   string `json:"git_branch"`
+	GitRepoName string `json:"git_repo_name"`
+	GitRepoID   uint   `json:"git_repo_id"`
+}
+
 func sourceFromAppAndGitSource(ctx context.Context, appProto *porterv1.PorterApp, gitSource GitSource) (porter_app.SourceType, *porter_app.Image, error) {
 	ctx, span := telemetry.NewSpan(ctx, "source-from-app-and-git-source")
 	defer span.End()

+ 0 - 29
api/server/router/porter_app.go

@@ -717,35 +717,6 @@ func getPorterAppRoutes(
 		Router:   r,
 	})
 
-	// POST /api/projects/{project_id}/clusters/{cluster_id}/apps/create -> porter_app.NewCreateAppHandler
-	createAppEndpoint := factory.NewAPIEndpoint(
-		&types.APIRequestMetadata{
-			Verb:   types.APIVerbCreate,
-			Method: types.HTTPVerbPost,
-			Path: &types.Path{
-				Parent:       basePath,
-				RelativePath: fmt.Sprintf("%s/create", relPathV2),
-			},
-			Scopes: []types.PermissionScope{
-				types.UserScope,
-				types.ProjectScope,
-				types.ClusterScope,
-			},
-		},
-	)
-
-	createAppHandler := porter_app.NewCreateAppHandler(
-		config,
-		factory.GetDecoderValidator(),
-		factory.GetResultWriter(),
-	)
-
-	routes = append(routes, &router.Route{
-		Endpoint: createAppEndpoint,
-		Handler:  createAppHandler,
-		Router:   r,
-	})
-
 	// POST /api/projects/{project_id}/clusters/{cluster_id}/apps/attach-env-group -> porter_app.NewAttachEnvGroupHandler
 	attachEnvGroupEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{

+ 1 - 0
dashboard/src/main/home/app-dashboard/apps/Addon.tsx

@@ -36,6 +36,7 @@ export const Addon: React.FC<AddonProps> = ({ addon, view }) => {
     const host = match(addon.config.type)
       .with("postgres", () => "postgres-postgres-hl")
       .with("redis", () => "redis-redis")
+      .exhaustive();
 
     return `${host}.${currentDeploymentTarget.namespace}.svc.cluster.local:${port}`;
   }, [currentDeploymentTarget, addon.name.value]);

+ 0 - 27
dashboard/src/shared/api.tsx

@@ -974,32 +974,6 @@ const getBranchHead = baseApi<
   }/${encodeURIComponent(pathParams.branch)}/head`;
 });
 
-const createApp = baseApi<
-  | {
-      name: string;
-      deployment_target_id: string;
-      type: "github";
-      git_repo_id: number;
-      git_branch: string;
-      git_repo_name: string;
-      porter_yaml_path: string;
-    }
-  | {
-      name: string;
-      deployment_target_id: string;
-      type: "docker-registry";
-      image: {
-        repository: string;
-        tag: string;
-      };
-    },
-  {
-    project_id: number;
-    cluster_id: number;
-  }
->("POST", (pathParams) => {
-  return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}/apps/create`;
-});
 
 const createAppTemplate = baseApi<
   {
@@ -3548,7 +3522,6 @@ export default {
   getDefaultDeploymentTarget,
   deleteDeploymentTarget,
   getBranchHead,
-  createApp,
   createAppTemplate,
   updateApp,
   appRun,