Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:master' into diversify-cluster-regions
Browse files Browse the repository at this point in the history
  • Loading branch information
199201shubhamsahu authored May 8, 2024
2 parents b47ae26 + d2ac619 commit b557586
Show file tree
Hide file tree
Showing 72 changed files with 17,813 additions and 787 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ jobs:
go-version-file: 'go.mod'
cache: false # because of https://github.com/golangci/golangci-lint-action/issues/135
- name: golangci-lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v3.7.1
with:
version: v1.56.2 # should match the version in Makefile
8 changes: 6 additions & 2 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ approvers:
- cheftako
- diviner524
- gemmahou
- jasonvigil
- jiefenghe
- maqiuyujoyce
- jingyih
- justinsb
- maqiuyujoyce
- roycaihw
- yuwenma
- ziyue-101
reviewers:
- acpana
Expand All @@ -18,9 +20,11 @@ reviewers:
- cheftako
- diviner524
- gemmahou
- jasonvigil
- jiefenghe
- maqiuyujoyce
- jingyih
- justinsb
- maqiuyujoyce
- roycaihw
- yuwenma
- ziyue-101
2 changes: 1 addition & 1 deletion build/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# This Dockerfile builds an image containing builds of all the binaries built
# from source (manager, webhook, etc.)
FROM golang:1.22.2 AS builder
FROM golang:1.22.3 AS builder

# Copy in the Go source code
WORKDIR /go/src/github.com/GoogleCloudPlatform/k8s-config-connector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ kind: IAMPolicyMember
metadata:
name: vertexaiindex-dep
spec:
member: serviceAccount:service-${PROJECT_NUMBER?}@gcp-sa-aiplatform.iam.gserviceaccount.com
memberFrom:
serviceIdentityRef:
name: vertexaiindex-dep
role: roles/storage.admin # required by vertex AI service agent to access test data
resourceRef:
apiVersion: storage.cnrm.cloud.google.com/v1beta1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
kind: ServiceIdentity
metadata:
name: vertexaiindex-dep
annotations:
cnrm.cloud.google.com/deletion-policy: "abandon"
spec:
projectRef:
# Replace ${PROJECT_ID?} with your project ID.
external: ${PROJECT_ID?}
resourceID: aiplatform.googleapis.com
24 changes: 22 additions & 2 deletions config/tests/samples/create/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package create

import (
"context"
"errors"
"fmt"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -237,19 +239,28 @@ func NewHarnessWithOptions(ctx context.Context, t *testing.T, opts *HarnessOptio
}
{
var wg sync.WaitGroup
var errsMutex sync.Mutex
var errs []error

for i := range crds {
crd := &crds[i]
wg.Add(1)
log.V(2).Info("loading crd", "name", crd.GetName())

go func() {
defer wg.Done()
if err := h.client.Create(ctx, crd.DeepCopy()); err != nil {
h.Fatalf("error creating crd %v: %v", crd.GroupVersionKind(), err)
errsMutex.Lock()
defer errsMutex.Unlock()
errs = append(errs, fmt.Errorf("error creating crd %v: %w", crd.GroupVersionKind(), err))
}
h.waitForCRDReady(crd)
}()
}
wg.Wait()
if len(errs) != 0 {
h.Fatalf("error creating crds: %v", errors.Join(errs...))
}
}
}

Expand Down Expand Up @@ -286,10 +297,15 @@ func NewHarnessWithOptions(ctx context.Context, t *testing.T, opts *HarnessOptio
testgcp.TestFolder2ID.Set("123451002")
testgcp.TestOrgID.Set("123450001")
testgcp.TestBillingAccountID.Set("123456-777777-000001")
testgcp.TestBillingAccountIDForBillingResources.Set("123456-777777-000003")
testgcp.IAMIntegrationTestsOrganizationID.Set("123450002")
testgcp.IAMIntegrationTestsBillingAccountID.Set("123456-777777-000002")
testgcp.TestAttachedClusterName.Set("xks-cluster")
testgcp.TestDependentNoNetworkProjectID.Set("mock-project")
testgcp.TestDependentOrgProjectID.Set("example-project-01")
testgcp.FirestoreTestProject.Set("cnrm-test-firestore")
testgcp.IdentityPlatformTestProject.Set("kcc-identity-platform")
testgcp.RecaptchaEnterpriseTestProject.Set("kcc-recaptcha-enterprise")

crm := h.getCloudResourceManagerClient(kccConfig.HTTPClient)
req := &cloudresourcemanagerv1.Project{
Expand Down Expand Up @@ -542,7 +558,7 @@ func MaybeSkip(t *testing.T, name string, resources []*unstructured.Unstructured
}

switch gvk.GroupKind() {
case schema.GroupKind{Group: "alloydb.googleapis.com", Kind: "AlloyDBCluster"}:
case schema.GroupKind{Group: "alloydb.cnrm.cloud.google.com", Kind: "AlloyDBCluster"}:

case schema.GroupKind{Group: "apikeys.cnrm.cloud.google.com", Kind: "APIKeysKey"}:

Expand Down Expand Up @@ -580,13 +596,17 @@ func MaybeSkip(t *testing.T, name string, resources []*unstructured.Unstructured
case schema.GroupKind{Group: "edgenetwork.cnrm.cloud.google.com", Kind: "EdgeNetworkSubnet"}:

case schema.GroupKind{Group: "logging.cnrm.cloud.google.com", Kind: "LoggingLogMetric"}:
case schema.GroupKind{Group: "logging.cnrm.cloud.google.com", Kind: "LoggingLogBucket"}:

case schema.GroupKind{Group: "monitoring.cnrm.cloud.google.com", Kind: "MonitoringDashboard"}:

case schema.GroupKind{Group: "networkservices.cnrm.cloud.google.com", Kind: "NetworkServicesMesh"}:

case schema.GroupKind{Group: "privateca.cnrm.cloud.google.com", Kind: "PrivateCACAPool"}:

case schema.GroupKind{Group: "pubsub.cnrm.cloud.google.com", Kind: "PubSubSchema"}:
case schema.GroupKind{Group: "pubsub.cnrm.cloud.google.com", Kind: "PubSubTopic"}:

case schema.GroupKind{Group: "redis.cnrm.cloud.google.com", Kind: "RedisInstance"}:

case schema.GroupKind{Group: "resourcemanager.cnrm.cloud.google.com", Kind: "Project"}:
Expand Down
9 changes: 0 additions & 9 deletions config/tests/samples/create/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,6 @@ var testDisabledList = map[string]bool{
// b/309167136
"alloydbbackup": true,
"restored-from-backup-cluster": true,
// Temporarily disable alloydbinstance sample tests as they raise alerts
// due to expected failures during create instance operation with service
// networking connection not being ready.
// Will enable this after adding fix for the alert mechanism or by adding
// precondition failure to not account this as an error.
"primary-instance": true,
"read-instance": true,
"secondary-instance": true,
"zonal-instance": true,
// This sample test need physical rack which is not suitable for e2e testing due to
// limited budget.
"edgecontainercluster-local-control-plane": true,
Expand Down
4 changes: 3 additions & 1 deletion experiments/composite/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/GoogleCloudPlatform/k8s-config-connector/experiments/composite

go 1.21.5
go 1.22

toolchain go1.22.3
2 changes: 1 addition & 1 deletion experiments/compositions/composition/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

# Build the manager binary
FROM golang:1.22 as builder
FROM golang:1.22.3 as builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
3 changes: 1 addition & 2 deletions experiments/compositions/composition/Dockerfile.inline
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

# ----------------- Build Container ---------------------------
# Build the go app.
# Explicitly set to latest vs golang:1.22
FROM golang:1.22 AS build-stage
FROM golang:1.22.3 AS build-stage

# Set destination for COPY
WORKDIR /go/src/app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ExpanderVersionSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// ImageRegistry is the designated registry for where to pull the named expander image
ImageRegistry string `json:"imageRegistry,omitempty"`
ImageRegistry string `json:"imageRegistry"`

// ValidVersions is a list of valid versions of the named expander
ValidVersions []string `json:"validVersions"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ spec:
type: string
type: array
required:
- imageRegistry
- validVersions
type: object
status:
Expand Down
6 changes: 4 additions & 2 deletions experiments/compositions/composition/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module google.com/composition

go 1.22.0
go 1.22

toolchain go1.22.1
toolchain go1.22.3

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/blang/semver v3.5.1+incompatible
github.com/go-logr/logr v1.4.1
github.com/gobuffalo/flect v1.0.2
github.com/google/go-cmp v0.6.0
Expand Down
6 changes: 6 additions & 0 deletions experiments/compositions/composition/go.sum

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 @@ -17,10 +17,13 @@ package controller
import (
"context"
"fmt"
"sort"
"strings"

semver "github.com/Masterminds/semver/v3"
compositionv1alpha1 "google.com/composition/api/v1alpha1"
"google.com/composition/pkg/containerexecutor/jobcontainerexecutor"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -178,13 +181,25 @@ func (r *ExpanderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
// ------------------- EXPANSION SECTION -----------------------
logger = loggerCR.WithName(expander.Name).WithName("Expand")

expanderVersion, expanderRegistry, err := r.getExpanderVersion(ctx, expander.Version, expander.Type)
if err != nil {
reason := "FailedGettingExpanderVersionCR"
if apierrors.IsNotFound(err) {
reason = "MissingExpanderVersionCR"
}
logger.Error(err, "Failed to get the ExpanderVersionCRD for %s, err: %s. Currently setting the version to v0.0.1.alpha", expander.Type, reason)
// The CR should be created before the specified expander can be used.
newStatus.AppendErrorCondition(expander.Name, err.Error(), "FailedGettingExpanderVersionCR")
return ctrl.Result{}, err
}

jf := jobcontainerexecutor.NewJobFactory(ctx, logger, r.Client, r.InputGVK, r.InputGVR,
r.Composition.Name, r.Composition.Namespace,
&inputcr, expander.Name, expander.Version, expander.Type, planNN.Name, r.ImageRegistry)
&inputcr, expander.Name, expanderVersion, expander.Type, planNN.Name, expanderRegistry)

// Create Expander Job and wait for the Job to complete
logger.Info("Creating expander job")
err := jf.Create()
err = jf.Create()
defer jf.CleanUp()
if err != nil {
// Reference for event API: Event(object runtime.Object, eventtype, reason, message string)
Expand Down Expand Up @@ -308,3 +323,35 @@ func (r *ExpanderReconciler) SetupWithManager(mgr ctrl.Manager, cr *unstructured
For(cr).
Complete(r)
}

func (r *ExpanderReconciler) getExpanderVersion(ctx context.Context, inputExpanderVersion string, expanderType string) (string, string, error) {
logger := log.FromContext(ctx)

var expanderVersionCR compositionv1alpha1.ExpanderVersion
var expanderVersion string
err := r.Client.Get(ctx, types.NamespacedName{Name: expanderType, Namespace: "composition-system"}, &expanderVersionCR)
if err != nil {
// The CR should be created before the specified expander can be used.
return "", "", err
}
expanderRegistry := expanderVersionCR.Spec.ImageRegistry

// Currently the version will default to latest if not set.
if inputExpanderVersion != "latest" {
expanderVersion = inputExpanderVersion
} else {
availableVersions := expanderVersionCR.Spec.ValidVersions
SemVerVersions := make([]*semver.Version, len(availableVersions))
for i, r := range availableVersions {
v, err := semver.NewVersion(r)
if err != nil {
logger.Info("Error parsing version: %s", err)
}
SemVerVersions[i] = v
}
sort.Sort(semver.Collection(SemVerVersions))
// The existing semver package sort only supports pure numbers.
expanderVersion = "v" + SemVerVersions[len(availableVersions)-1].String() + ".alpha"
}
return expanderVersion, expanderRegistry, nil
}
1 change: 1 addition & 0 deletions experiments/compositions/composition/release/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ spec:
type: string
type: array
required:
- imageRegistry
- validVersions
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

apiVersion: composition.google.com/v1alpha1
kind: ExpanderVersion
metadata:
name: jinja2
namespace: composition-system
spec:
imageRegistry: gcr.io/krmapihosting-release
validVersions:
# current golang semver package only support version comparison
# in the format of `v{num}.{num}.{num}-{alphabet}`, `v{num}.{num}.{num}` and `{num}.{num}.{num}`.
# Removing the `.alpha` here for now. Will be added back in the test.
- v0.0.1
- v0.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ spec:
type: string
type: array
required:
- imageRegistry
- validVersions
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
FacadeCRDManifests = "../../release/facade_crds.yaml"
KindOperatorManifests = "../../release/kind/operator.yaml"
CCOperatorManifests = "../../release/cc/operator.yaml"
ExpanderManifests = "../../release/kind/jinja2_expander_version.yaml"
)

type ClusterUser interface {
Expand Down Expand Up @@ -102,7 +103,7 @@ func CreateKindClusters(clusterCount int, images string) {
// that adds these images
strings.Split(images, ","),
// and installs these manifests
[]string{CRDManifests, KindOperatorManifests},
[]string{CRDManifests, KindOperatorManifests, ExpanderManifests},
// and waits for these deployments to be ready
[]types.NamespacedName{
{Namespace: "composition-system", Name: "composition-controller-manager"},
Expand Down
Loading

0 comments on commit b557586

Please sign in to comment.