Skip to content

Commit

Permalink
Make sslMode optional
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed May 6, 2022
1 parent 293c66b commit 6b54639
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 24 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,20 @@ jobs:
# We're using docker buildx, which doesn't actually load the images it
# builds by default. Specifying --load does so.
BUILD_ARGS: "--load"

- name: Publish Artifacts to GitHub
uses: actions/upload-artifact@v2
with:
name: output
path: _output/**

- name: Login to Docker
uses: docker/login-action@v1
if: env.DOCKER_USR != ''
with:
username: ${{ secrets.DOCKER_USR }}
password: ${{ secrets.DOCKER_PSW }}

- name: Publish Artifacts to S3 and Docker Hub
run: make -j2 publish BRANCH_NAME=${GITHUB_REF##*/}
if: env.AWS_USR != '' && env.DOCKER_USR != ''
Expand All @@ -313,7 +313,7 @@ jobs:
GIT_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCS_GIT_USR: ${{ secrets.UPBOUND_BOT_GITHUB_USR }}
DOCS_GIT_PSW: ${{ secrets.UPBOUND_BOT_GITHUB_PSW }}

- name: Promote Artifacts in S3 and Docker Hub
if: github.ref == 'refs/heads/master' && env.AWS_USR != '' && env.DOCKER_USR != ''
run: make -j2 promote
Expand All @@ -322,4 +322,3 @@ jobs:
CHANNEL: master
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_USR }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PSW }}

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/vendor
/.vendor-new
.vscode
/.idea

.cache
.work
Expand Down
9 changes: 0 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,4 @@ crossplane.help:

help-special: crossplane.help

# NOTE(hasheddan): the build submodule currently overrides XDG_CACHE_HOME in
# order to force the Helm 3 to use the .work/helm directory. This causes Go on
# Linux machines to use that directory as the build cache as well. We should
# adjust this behavior in the build submodule because it is also causing Linux
# users to duplicate their build cache, but for now we just make it easier to
# identify its location in CI so that we cache between builds.
go.cachedir:
@go env GOCACHE

.PHONY: crossplane.help help-special
4 changes: 2 additions & 2 deletions apis/postgresql/v1alpha1/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type ProviderConfigSpec struct {
// PostgreSQL instance
// +kubebuilder:validation:Enum=disable;require;verify-ca;verify-full
// +kubebuilder:default=verify-full
// +kubebuilder:validation:Required
SSLMode string `json:"sslMode"`
// +kubebuilder:validation:Optional
SSLMode *string `json:"sslMode,omitempty"`
}

const (
Expand Down
5 changes: 5 additions & 0 deletions apis/postgresql/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ spec:
type: string
required:
- credentials
- sslMode
type: object
status:
description: A ProviderConfigStatus reflects the observed state of a ProviderConfig.
Expand Down
26 changes: 26 additions & 0 deletions pkg/clients/sql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2022 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clients

// ToString converts the supplied string pointer to a string,
// returning an empty string if the pointer is nil.
func ToString(s *string) string {
if s != nil {
return *s
}
return ""
}
3 changes: 2 additions & 1 deletion pkg/controller/postgresql/database/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -119,7 +120,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.Wrap(err, errGetSecret)
}

return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode)}, nil
return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode))}, nil
}

type external struct{ db xsql.DB }
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/postgresql/extension/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -112,10 +113,10 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
// We do not want to create an extension on the default DB
// if the user was expecting a database name to be resolved.
if cr.Spec.ForProvider.Database != nil {
return &external{db: c.newDB(s.Data, *cr.Spec.ForProvider.Database, pc.Spec.SSLMode)}, nil
return &external{db: c.newDB(s.Data, *cr.Spec.ForProvider.Database, clients.ToString(pc.Spec.SSLMode))}, nil
}

return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode)}, nil
return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode))}, nil
}

type external struct{ db xsql.DB }
Expand Down Expand Up @@ -179,7 +180,7 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
return managed.ExternalCreation{}, errors.Wrap(c.db.Exec(ctx, xsql.Query{String: b.String()}), errCreateExtension)
}

func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.ExternalUpdate, error) { //nolint:gocyclo
func (c *external) Update(_ context.Context, mg resource.Managed) (managed.ExternalUpdate, error) { //nolint:gocyclo
_, ok := mg.(*v1alpha1.Extension)
if !ok {
return managed.ExternalUpdate{}, errors.New(errNotExtension)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/postgresql/grant/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -120,7 +121,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.Wrap(err, errGetSecret)
}
return &external{
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode),
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode)),
kube: c.kube,
}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/postgresql/role/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -122,7 +123,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
}

return &external{
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode),
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode)),
kube: c.kube,
}, nil
}
Expand Down

0 comments on commit 6b54639

Please sign in to comment.