Skip to content

Commit

Permalink
remove deprecated code for chart 0.10.8
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
  • Loading branch information
andreafalzetti committed Apr 23, 2024
1 parent c7f0a8f commit 8771320
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 261 deletions.
58 changes: 1 addition & 57 deletions pkg/okteto/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package okteto
import (
"context"
"errors"
"strings"

"github.com/okteto/okteto/pkg/constants"
oktetoErrors "github.com/okteto/okteto/pkg/errors"
oktetoLog "github.com/okteto/okteto/pkg/log"
Expand Down Expand Up @@ -61,10 +59,6 @@ type authMutationStruct struct {
Response userMutation `graphql:"auth(code: $code, source: $source)"`
}

type deprecatedAuthMutationStruct struct {
Response deprecatedUserMutation `graphql:"auth(code: $code, source: $source)"`
}

type userMutation struct {
Id graphql.String
Name graphql.String
Expand All @@ -80,19 +74,6 @@ type userMutation struct {
Analytics graphql.Boolean `graphql:"telemetryEnabled"`
}

type deprecatedUserMutation struct {
Id graphql.String
Name graphql.String
Namespace graphql.String
Email graphql.String
ExternalID graphql.String `graphql:"externalID"`
Token graphql.String
Registry graphql.String
Buildkit graphql.String
Certificate graphql.String
New graphql.Boolean
}

// Auth authenticates in okteto with an OAuth code
func (c *Client) Auth(ctx context.Context, code string) (*types.User, error) {
user, err := c.authUser(ctx, code)
Expand All @@ -102,7 +83,7 @@ func (c *Client) Auth(ctx context.Context, code string) (*types.User, error) {
return nil, errGitHubNotVerifiedEmail
}
// This error is sent at the mutation with Metadata. Our current client for GraphQL does not support this kind of errors,
// so the information regarding metada is lost here. Message is still communicated so we can check the error
// so the information regarding metada is lost here. Message is still communicated, so we can check the error
// https://github.com/okteto/okteto/issues/2926
if IsErrGithubMissingBusinessEmail(err) {
return nil, err
Expand Down Expand Up @@ -134,12 +115,6 @@ func (c *Client) authUser(ctx context.Context, code string) (*types.User, error)

err := mutate(ctx, &mutation, queryVariables, c.client)
if err != nil {
if strings.Contains(err.Error(), "Cannot query field \"globalNamespace\" on type \"me\"") {
return c.deprecatedAuthUser(ctx, code)
}
if strings.Contains(err.Error(), "Cannot query field \"telemetryEnabled\" on type \"me\"") {
return c.deprecatedAuthUser(ctx, code)
}
return nil, err
}

Expand All @@ -164,37 +139,6 @@ func (c *Client) authUser(ctx context.Context, code string) (*types.User, error)
return user, nil
}

// TODO: Remove this code when okteto char 0.10.8 is deprecated
func (c *Client) deprecatedAuthUser(ctx context.Context, code string) (*types.User, error) {
var mutation deprecatedAuthMutationStruct
queryVariables := map[string]interface{}{
"code": graphql.String(code),
"source": graphql.String(cliSource),
}

err := mutate(ctx, &mutation, queryVariables, c.client)
if err != nil {
return nil, err
}

user := &types.User{
ID: string(mutation.Response.Id),
Name: string(mutation.Response.Name),
Namespace: string(mutation.Response.Namespace),
Email: string(mutation.Response.Email),
ExternalID: string(mutation.Response.ExternalID),
Token: string(mutation.Response.Token),
New: bool(mutation.Response.New),
Registry: string(mutation.Response.Registry),
Buildkit: string(mutation.Response.Buildkit),
Certificate: string(mutation.Response.Certificate),
GlobalNamespace: constants.DefaultGlobalNamespace,
Analytics: true,
}

return user, nil
}

func getGlobalNamespace(g string) string {
if g == "" {
return constants.DefaultGlobalNamespace
Expand Down
74 changes: 0 additions & 74 deletions pkg/okteto/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,77 +202,3 @@ func TestAuthGQLCall(t *testing.T) {
})
}
}

func TestDeprecatedAuth(t *testing.T) {
type input struct {
client fakeGraphQLClient
}
type expected struct {
user *types.User
err error
}
tests := []struct {
expected expected
input input
name string
}{
{
name: "error",
input: input{
client: fakeGraphQLClient{
err: assert.AnError,
},
},
expected: expected{
err: assert.AnError,
},
},
{
name: "return user",
input: input{
client: fakeGraphQLClient{
mutationResult: &deprecatedAuthMutationStruct{
Response: deprecatedUserMutation{
Id: "test",
Name: "test",
Namespace: "test",
Email: "test",
ExternalID: "test",
Token: "test",
New: true,
Registry: "test",
Buildkit: "test",
Certificate: "test",
},
},
},
},
expected: expected{
user: &types.User{
Name: "test",
Namespace: "test",
Email: "test",
ExternalID: "test",
Token: "test",
New: true,
Registry: "test",
Buildkit: "test",
Certificate: "test",
ID: "test",
GlobalNamespace: constants.DefaultGlobalNamespace,
Analytics: true,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := Client{
client: tt.input.client,
}
u, err := c.deprecatedAuthUser(context.Background(), "")
assert.ErrorIs(t, err, tt.expected.err)
assert.Equal(t, tt.expected.user, u)
})
}
}
58 changes: 0 additions & 58 deletions pkg/okteto/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,10 @@ type destroyPipelineWithVolumesMutation struct {
Response destroyPipelineResponse `graphql:"destroyGitRepository(name: $name, space: $space, destroyVolumes: $destroyVolumes)"`
}

type deprecatedDestroyPipelineWithVolumesMutation struct {
Response deprecatedDestroyPipelineResponse `graphql:"destroyGitRepository(name: $name, space: $space, destroyVolumes: $destroyVolumes)"`
}

type destroyPipelineWithoutVolumesMutation struct {
Response destroyPipelineResponse `graphql:"destroyGitRepository(name: $name, space: $space)"`
}

type deprecatedDestroyPipelineWithoutVolumesMutation struct {
Response deprecatedDestroyPipelineResponse `graphql:"destroyGitRepository(name: $name, space: $space)"`
}

type getPipelineResources struct {
Response previewResourcesStatus `graphql:"space(id: $id)"`
}
Expand Down Expand Up @@ -111,10 +103,6 @@ type destroyPipelineResponse struct {
GitDeploy gitDeployInfoWithRepoInfo
}

type deprecatedDestroyPipelineResponse struct {
GitDeploy gitDeployInfoWithRepoInfo
}

// Deploy creates a pipeline
func (c *pipelineClient) Deploy(ctx context.Context, opts types.PipelineDeployOptions) (*types.GitDeployResponse, error) {
oktetoLog.Infof("deploying pipeline '%s' mutation on %s", opts.Name, opts.Namespace)
Expand Down Expand Up @@ -235,9 +223,6 @@ func (c *pipelineClient) Destroy(ctx context.Context, name, namespace string, de
}
err := mutate(ctx, &mutation, queryVariables, c.client)
if err != nil {
if strings.Contains(err.Error(), "Cannot query field \"action\" on type \"GitDeploy\"") {
return c.deprecatedDestroy(ctx, name, namespace, destroyVolumes)
}
return nil, fmt.Errorf("failed to deploy pipeline: %w", err)
}
gitDeployResponse.Action = &types.Action{
Expand All @@ -259,9 +244,6 @@ func (c *pipelineClient) Destroy(ctx context.Context, name, namespace string, de
}
err := mutate(ctx, &mutation, queryVariables, c.client)
if err != nil {
if strings.Contains(err.Error(), "Cannot query field \"action\" on type \"GitDeploy\"") {
return c.deprecatedDestroy(ctx, name, namespace, destroyVolumes)
}
return nil, fmt.Errorf("failed to deploy pipeline: %w", err)
}
gitDeployResponse.Action = &types.Action{
Expand All @@ -281,46 +263,6 @@ func (c *pipelineClient) Destroy(ctx context.Context, name, namespace string, de
return gitDeployResponse, nil
}

// TODO: Remove this function when okteto chart 0.10.8 is no longer supported
func (c *pipelineClient) deprecatedDestroy(ctx context.Context, name, namespace string, destroyVolumes bool) (*types.GitDeployResponse, error) {
oktetoLog.Infof("destroy pipeline: %s/%s", namespace, name)
gitDeployResponse := &types.GitDeployResponse{}
if destroyVolumes {
var mutation deprecatedDestroyPipelineWithVolumesMutation

queryVariables := map[string]interface{}{
"name": graphql.String(name),
"destroyVolumes": graphql.Boolean(destroyVolumes),
"space": graphql.String(namespace),
}
err := mutate(ctx, &mutation, queryVariables, c.client)
if err != nil {
return nil, fmt.Errorf("failed to deploy pipeline: %w", err)
}
gitDeployResponse.GitDeploy = &types.GitDeploy{
ID: string(mutation.Response.GitDeploy.Id),
Status: string(mutation.Response.GitDeploy.Status),
}
} else {
var mutation deprecatedDestroyPipelineWithoutVolumesMutation
queryVariables := map[string]interface{}{
"name": graphql.String(name),
"space": graphql.String(namespace),
}
err := mutate(ctx, &mutation, queryVariables, c.client)
if err != nil {
return nil, fmt.Errorf("failed to deploy pipeline: %w", err)
}
gitDeployResponse.GitDeploy = &types.GitDeploy{
ID: string(mutation.Response.GitDeploy.Id),
Status: string(mutation.Response.GitDeploy.Status),
}
}

oktetoLog.Infof("destroy pipeline: %+v", gitDeployResponse.GitDeploy.Status)
return gitDeployResponse, nil
}

// GetResourcesStatus returns the status of deployments statefulsets and jobs
func (c *pipelineClient) GetResourcesStatus(ctx context.Context, name, namespace string) (map[string]string, error) {
oktetoLog.Infof("get resource status started for pipeline: %s/%s", namespace, name)
Expand Down
72 changes: 0 additions & 72 deletions pkg/okteto/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ type getContextFileQuery struct {
ContextFileJSON string `graphql:"contextFile"`
}

type getDeprecatedContextQuery struct {
User deprecatedUserQuery `graphql:"user"`
Cred credQuery `graphql:"credentials(space: $cred)"`
Secrets []secretQuery `graphql:"getGitDeploySecrets"`
}

type getRegistryCredentialsQuery struct {
RegistryCredentials registryCredsQuery `graphql:"registryCredentials(registryUrl: $regHost)"`
}
Expand All @@ -75,20 +69,6 @@ type userQuery struct {
Analytics graphql.Boolean `graphql:"telemetryEnabled"`
}

// TODO: Remove this code when users are in okteto chart > 0.10.8
type deprecatedUserQuery struct {
Id graphql.String
Name graphql.String
Namespace graphql.String
Email graphql.String
ExternalID graphql.String `graphql:"externalID"`
Token graphql.String
Registry graphql.String
Buildkit graphql.String
Certificate graphql.String
New graphql.Boolean
}

type secretQuery struct {
Name graphql.String
Value graphql.String
Expand Down Expand Up @@ -133,12 +113,6 @@ func (c *userClient) GetContext(ctx context.Context, ns string) (*types.UserCont
}
err := query(ctx, &queryStruct, variables, c.client)
if err != nil {
if strings.Contains(err.Error(), "Cannot query field \"globalNamespace\" on type \"me\"") {
return c.deprecatedGetUserContext(ctx)
}
if strings.Contains(err.Error(), "Cannot query field \"telemetryEnabled\" on type \"me\"") {
return c.deprecatedGetUserContext(ctx)
}
return nil, err
}

Expand Down Expand Up @@ -202,52 +176,6 @@ func (c *userClient) GetUserSecrets(ctx context.Context) ([]types.Secret, error)
return secrets, nil
}

// TODO: Remove this code when users are in okteto chart > 0.10.8
func (c *userClient) deprecatedGetUserContext(ctx context.Context) (*types.UserContext, error) {
var queryStruct getDeprecatedContextQuery
variables := map[string]interface{}{
"cred": graphql.String(""),
}
err := query(ctx, &queryStruct, variables, c.client)
if err != nil {
return nil, err
}

secrets := make([]types.Secret, 0)
for _, secret := range queryStruct.Secrets {
if !strings.Contains(string(secret.Name), ".") {
secrets = append(secrets, types.Secret{
Name: string(secret.Name),
Value: string(secret.Value),
})
}
}
result := &types.UserContext{
User: types.User{
ID: string(queryStruct.User.Id),
Name: string(queryStruct.User.Name),
Namespace: string(queryStruct.User.Namespace),
Email: string(queryStruct.User.Email),
ExternalID: string(queryStruct.User.ExternalID),
Token: string(queryStruct.User.Token),
New: bool(queryStruct.User.New),
Registry: string(queryStruct.User.Registry),
Buildkit: string(queryStruct.User.Buildkit),
Certificate: string(queryStruct.User.Certificate),
GlobalNamespace: constants.DefaultGlobalNamespace,
Analytics: true,
},
Secrets: secrets,
Credentials: types.Credential{
Server: string(queryStruct.Cred.Server),
Certificate: string(queryStruct.Cred.Certificate),
Token: string(queryStruct.Cred.Token),
Namespace: string(queryStruct.Cred.Namespace),
},
}
return result, nil
}

func (c *userClient) GetClusterCertificate(ctx context.Context, cluster, ns string) ([]byte, error) {
var queryStruct getContextFileQuery
if err := query(ctx, &queryStruct, nil, c.client); err != nil {
Expand Down

0 comments on commit 8771320

Please sign in to comment.