Skip to content

Commit

Permalink
WIP: Implement direct controller for Spanner Database
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvigil committed Jun 6, 2024
1 parent ccb46d9 commit e5f9886
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 16 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
cloud.google.com/go/profiler v0.1.0
cloud.google.com/go/resourcemanager v1.9.7
cloud.google.com/go/securesourcemanager v0.1.5
cloud.google.com/go/spanner v1.60.0
contrib.go.opencensus.io/exporter/prometheus v0.1.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.62.0
github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp v0.0.0-00010101000000-000000000000
Expand Down
5 changes: 4 additions & 1 deletion go.sum

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

2 changes: 2 additions & 0 deletions hack/compare-mock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set -x

export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)

export KCC_USE_DIRECT_RECONCILERS=SpannerDatabase

rm -rf $(pwd)/artifactz/mocks

RUN_TESTS=TestAllInSeries/$1
Expand Down
51 changes: 51 additions & 0 deletions pkg/controller/direct/directbase/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2024 Google LLC
//
// 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 directbase

import (
"errors"

"github.com/googleapis/gax-go/v2/apierror"
"k8s.io/klog/v2"
)

func ValueOf[T any](p *T) T {
var v T
if p != nil {
v = *p
}
return v
}

// HasHTTPCode returns true if the given error is an HTTP response with the given code.
func HasHTTPCode(err error, code int) bool {
if err == nil {
return false
}
apiError := &apierror.APIError{}
if errors.As(err, &apiError) {
if apiError.HTTPCode() == code {
return true
}
} else {
klog.Warningf("unexpected error type %T", err)
}
return false
}

// IsNotFound returns true if the given error is an HTTP 404.
func IsNotFound(err error) bool {
return HasHTTPCode(err, 404)
}
1 change: 1 addition & 0 deletions pkg/controller/direct/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ import (
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/gkehub"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/logging"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/resourcemanager"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/spanner"
)
Loading

0 comments on commit e5f9886

Please sign in to comment.