Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ProviderConfig CRD types #2810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 deletions pkg/apis/providerconfig/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,62 @@ type ProviderConfig struct {
Status ProviderConfigStatus `json:"status,omitempty"`
}

// ProviderConfigSpec is the spec for a resource
// ProviderConfigSpec defines the desired state of ProviderConfig.
// +k8s:openapi-gen=true
type ProviderConfigSpec struct {
// The ID of the project where the provider config is to be created.
ProjectID string `json:"projectID,omitempty"`
// The project number where the provider config is to be created.
ProjectNumber int64 `json:"projectNumber,omitempty"`
// The network configuration for the provider config.
NetworkConfig *NetworkConfig `json:"networkConfig,omitempty"`
// ProjectNumber is the GCP project number.
//
// +kubebuilder:validation:Minimum=0
// +(Validation done in accordance with go/elysium/project_ids#project-number)
ProjectNumber int64 `json:"projectNumber"`
// ProjectID is the GCP Project ID.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=30
// +(Validation done in accordance with https://cloud.google.com/resource-manager/docs/creating-managing-projects#before_you_begin)
ProjectID string `json:"projectID"`
// PSC connection ID of the PSC endpoint.
//
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Optional
PSCConnectionID int64 `json:"pscConnectionID"`
NetworkConfig ProviderNetworkConfig `json:"networkConfig"`
}

// NetworkConfig specifies the network configuration for the provider config.
type NetworkConfig struct {
// ProviderNetworkConfig specifies the network configuration for the provider config.
type ProviderNetworkConfig struct {
// The network where the provider config is to be created.
Network string `json:"network,omitempty"`
// The default subnetwork where the provider config is to be created.
DefaultSubnetwork string `json:"defaultSubnetwork,omitempty"`
SubnetInfo ProviderConfigSubnetInfo `json:"subnetInfo"`
}

// ProviderConfigStatus is the status for a ProviderConfig resource
// ProviderConfigSubnetInfo defines the subnet configuration.
type ProviderConfigSubnetInfo struct {
// Subnetwork is the name of the subnetwork in the format projects/{project}/regions/{region}/subnetworks/{subnet}.
Subnetwork string `json:"subnetwork"`
// The primary IP range of the subnet in CIDR notation (e.g.,`10.0.0.0/16`).
CIDR string `json:"cidr"`
// PodRanges contains the Pod CIDR ranges that are part of this Subnet.
PodRanges []ProviderConfigSecondaryRange `json:"podRanges"`
}

// ProviderConfigSecondaryRange describes the configuration of a SecondaryRange.
type ProviderConfigSecondaryRange struct {
// The name of the secondary range.
Name string `json:"name"`
// The secondary IP range in CIDR notation (e.g.,`10.0.0.0/16`).
CIDR string `json:"cidr"`
}

// ProviderConfigStatus defines the current state of ProviderConfig.
type ProviderConfigStatus struct {
// Conditions describe the current conditions of the ProviderConfig.
//
// +listType=map
// +listMapKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
86 changes: 64 additions & 22 deletions pkg/apis/providerconfig/v1/zz_generated.deepcopy.go

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

25 changes: 18 additions & 7 deletions pkg/apis/providerconfig/v1/zz_generated.openapi.go

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

4 changes: 2 additions & 2 deletions pkg/multiproject/gce/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func (g *GCEFake) GCEForProviderConfig(providerConfig *v1.ProviderConfig, logger
updatedConfig := g.defaultTestClusterValues
updatedConfig.ProjectID = providerConfig.Spec.ProjectID
updatedConfig.NetworkURL = fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", providerConfig.Spec.ProjectID, providerConfig.Spec.NetworkConfig.Network)
updatedConfig.SubnetworkURL = fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s", providerConfig.Spec.ProjectID, updatedConfig.Region, providerConfig.Spec.NetworkConfig.DefaultSubnetwork)
updatedConfig.SubnetworkURL = fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s", providerConfig.Spec.ProjectID, updatedConfig.Region, providerConfig.Spec.NetworkConfig.SubnetInfo.Subnetwork)
logger.Info("Creating GCEFake for provider config", "providerConfig", providerConfig.Name, "updatedConfig", updatedConfig)
fakeCloud := cloudgce.NewFakeGCECloud(updatedConfig)
_, err := createNetwork(fakeCloud, providerConfig.Spec.NetworkConfig.Network)
if err != nil {
return nil, err
}
_, err = createSubnetwork(fakeCloud, providerConfig.Spec.NetworkConfig.DefaultSubnetwork, providerConfig.Spec.NetworkConfig.Network)
_, err = createSubnetwork(fakeCloud, providerConfig.Spec.NetworkConfig.SubnetInfo.Subnetwork, providerConfig.Spec.NetworkConfig.Network)
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/multiproject/gce/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ func TestNewGCEForProviderConfig(t *testing.T) {
},
Spec: v1.ProviderConfigSpec{
ProjectID: "custom-project-id",
NetworkConfig: &v1.NetworkConfig{
Network: "custom-network",
DefaultSubnetwork: "custom-subnetwork",
NetworkConfig: v1.ProviderNetworkConfig{
Network: "custom-network",
SubnetInfo: v1.ProviderConfigSubnetInfo{
Subnetwork: "custom-subnetwork",
},
},
},
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/multiproject/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ func generateConfigForProviderConfig(defaultConfigContent string, providerConfig
globalSection.Key(tokenBodyKey).SetValue(newTokenBody)

// Update NetworkName and SubnetworkName
if providerConfig.Spec.NetworkConfig != nil {
networkNameKey := "network-name"
globalSection.Key(networkNameKey).SetValue(providerConfig.Spec.NetworkConfig.Network)
networkNameKey := "network-name"
globalSection.Key(networkNameKey).SetValue(providerConfig.Spec.NetworkConfig.Network)

subnetworkNameKey := "subnetwork-name"
globalSection.Key(subnetworkNameKey).SetValue(providerConfig.Spec.NetworkConfig.DefaultSubnetwork)
}
subnetworkNameKey := "subnetwork-name"
globalSection.Key(subnetworkNameKey).SetValue(providerConfig.Spec.NetworkConfig.SubnetInfo.Subnetwork)

// Write the modified config content to a string with custom options
var modifiedConfigContent bytes.Buffer
Expand Down
16 changes: 10 additions & 6 deletions pkg/multiproject/gce/gce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ subnetwork-name = default-subnetwork
Spec: v1.ProviderConfigSpec{
ProjectID: "providerconfig-project-id",
ProjectNumber: 654321,
NetworkConfig: &v1.NetworkConfig{
Network: "providerconfig-network-url",
DefaultSubnetwork: "providerconfig-subnetwork-url",
NetworkConfig: v1.ProviderNetworkConfig{
Network: "providerconfig-network-url",
SubnetInfo: v1.ProviderConfigSubnetInfo{
Subnetwork: "providerconfig-subnetwork-url",
},
},
},
},
Expand Down Expand Up @@ -196,9 +198,11 @@ other-field = other-value
Spec: v1.ProviderConfigSpec{
ProjectID: "providerconfig-project-id",
ProjectNumber: 654321,
NetworkConfig: &v1.NetworkConfig{
Network: "providerconfig-network-url",
DefaultSubnetwork: "providerconfig-subnetwork-url",
NetworkConfig: v1.ProviderNetworkConfig{
Network: "providerconfig-network-url",
SubnetInfo: v1.ProviderConfigSubnetInfo{
Subnetwork: "providerconfig-subnetwork-url",
},
},
},
},
Expand Down
24 changes: 15 additions & 9 deletions pkg/multiproject/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ func TestStartProviderConfigIntegration(t *testing.T) {
Spec: providerconfigv1.ProviderConfigSpec{
ProjectID: "my-project",
ProjectNumber: 12345,
NetworkConfig: &providerconfigv1.NetworkConfig{
Network: "my-network",
DefaultSubnetwork: "my-subnetwork",
NetworkConfig: providerconfigv1.ProviderNetworkConfig{
Network: "my-network",
SubnetInfo: providerconfigv1.ProviderConfigSubnetInfo{
Subnetwork: "my-subnetwork",
},
},
},
},
Expand Down Expand Up @@ -112,9 +114,11 @@ func TestStartProviderConfigIntegration(t *testing.T) {
Spec: providerconfigv1.ProviderConfigSpec{
ProjectID: "project-1",
ProjectNumber: 1111,
NetworkConfig: &providerconfigv1.NetworkConfig{
Network: "my-network-1",
DefaultSubnetwork: "my-subnetwork-1",
NetworkConfig: providerconfigv1.ProviderNetworkConfig{
Network: "my-network-1",
SubnetInfo: providerconfigv1.ProviderConfigSubnetInfo{
Subnetwork: "my-subnetwork-1",
},
},
},
},
Expand All @@ -126,9 +130,11 @@ func TestStartProviderConfigIntegration(t *testing.T) {
Spec: providerconfigv1.ProviderConfigSpec{
ProjectID: "project-2",
ProjectNumber: 2222,
NetworkConfig: &providerconfigv1.NetworkConfig{
Network: "my-network-2",
DefaultSubnetwork: "my-subnetwork-2",
NetworkConfig: providerconfigv1.ProviderNetworkConfig{
Network: "my-network-2",
SubnetInfo: providerconfigv1.ProviderConfigSubnetInfo{
Subnetwork: "my-subnetwork-2",
},
},
},
},
Expand Down