Skip to content

Commit

Permalink
Update API slice fields to not use pointers
Browse files Browse the repository at this point in the history
This is causing problems with the Kubernetes 1.19 code-generator.
A nil entry in these slices wouldn't be valid anyways, so this should have no impact.
  • Loading branch information
rifelpet committed Aug 24, 2020
1 parent 83d299d commit 7d9f0a0
Show file tree
Hide file tree
Showing 31 changed files with 158 additions and 208 deletions.
4 changes: 2 additions & 2 deletions examples/kops-api-example/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func up(ctx context.Context) error {
}

for _, etcdClusterName := range cloudup.EtcdClusters {
etcdCluster := &api.EtcdClusterSpec{
etcdCluster := api.EtcdClusterSpec{
Name: etcdClusterName,
}
for _, masterZone := range masterZones {
etcdMember := &api.EtcdMemberSpec{
etcdMember := api.EtcdMemberSpec{
Name: masterZone,
InstanceGroup: fi.String(masterZone),
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type ClusterSpec struct {
// A collection of files assets for deployed cluster wide
FileAssets []FileAssetSpec `json:"fileAssets,omitempty"`
// EtcdClusters stores the configuration for each cluster
EtcdClusters []*EtcdClusterSpec `json:"etcdClusters,omitempty"`
EtcdClusters []EtcdClusterSpec `json:"etcdClusters,omitempty"`
// Component configurations
Containerd *ContainerdConfig `json:"containerd,omitempty"`
Docker *DockerConfig `json:"docker,omitempty"`
Expand Down Expand Up @@ -204,7 +204,7 @@ type NodeAuthorizerSpec struct {
// Authorizer is the authorizer to use
Authorizer string `json:"authorizer,omitempty"`
// Features is a series of authorizer features to enable or disable
Features *[]string `json:"features,omitempty"`
Features []string `json:"features,omitempty"`
// Image is the location of container
Image string `json:"image,omitempty"`
// NodeURL is the node authorization service url
Expand Down Expand Up @@ -443,7 +443,7 @@ type EtcdClusterSpec struct {
// We default to manager for kubernetes 1.11 or if the manager is configured; otherwise standalone.
Provider EtcdProviderType `json:"provider,omitempty"`
// Members stores the configurations for each member of the cluster (including the data volume)
Members []*EtcdMemberSpec `json:"etcdMembers,omitempty"`
Members []EtcdMemberSpec `json:"etcdMembers,omitempty"`
// EnableEtcdTLS indicates the etcd service should use TLS between peers and clients
EnableEtcdTLS bool `json:"enableEtcdTLS,omitempty"`
// EnableTLSAuth indicates client and peer TLS auth should be enforced
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kops/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ type InstanceGroupSpec struct {
// RootVolumeEncryption enables EBS root volume encryption for an instance
RootVolumeEncryption *bool `json:"rootVolumeEncryption,omitempty"`
// Volumes is a collection of additional volumes to create for instances within this InstanceGroup
Volumes []*VolumeSpec `json:"volumes,omitempty"`
Volumes []VolumeSpec `json:"volumes,omitempty"`
// VolumeMounts a collection of volume mounts
VolumeMounts []*VolumeMountSpec `json:"volumeMounts,omitempty"`
VolumeMounts []VolumeMountSpec `json:"volumeMounts,omitempty"`
// Subnets is the names of the Subnets (as specified in the Cluster) where machines in this instance group should be placed
Subnets []string `json:"subnets,omitempty"`
// Zones is the names of the Zones where machines in this instance group should be placed
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/kops/v1alpha2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type ClusterSpec struct {
// A collection of files assets for deployed cluster wide
FileAssets []FileAssetSpec `json:"fileAssets,omitempty"`
// EtcdClusters stores the configuration for each cluster
EtcdClusters []*EtcdClusterSpec `json:"etcdClusters,omitempty"`
EtcdClusters []EtcdClusterSpec `json:"etcdClusters,omitempty"`
// Component configurations
Containerd *ContainerdConfig `json:"containerd,omitempty"`
Docker *DockerConfig `json:"docker,omitempty"`
Expand Down Expand Up @@ -202,7 +202,7 @@ type NodeAuthorizerSpec struct {
// Authorizer is the authorizer to use
Authorizer string `json:"authorizer,omitempty"`
// Features is a series of authorizer features to enable or disable
Features *[]string `json:"features,omitempty"`
Features []string `json:"features,omitempty"`
// Image is the location of container
Image string `json:"image,omitempty"`
// NodeURL is the node authorization service url
Expand Down Expand Up @@ -439,7 +439,7 @@ type EtcdClusterSpec struct {
// We default to manager for kubernetes 1.11 or if the manager is configured; otherwise standalone.
Provider EtcdProviderType `json:"provider,omitempty"`
// Members stores the configurations for each member of the cluster (including the data volume)
Members []*EtcdMemberSpec `json:"etcdMembers,omitempty"`
Members []EtcdMemberSpec `json:"etcdMembers,omitempty"`
// EnableEtcdTLS indicates the etcd service should use TLS between peers and clients
EnableEtcdTLS bool `json:"enableEtcdTLS,omitempty"`
// EnableTLSAuth indicates client and peer TLS auth should be enforced
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kops/v1alpha2/instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ type InstanceGroupSpec struct {
// RootVolumeEncryption enables EBS root volume encryption for an instance
RootVolumeEncryption *bool `json:"rootVolumeEncryption,omitempty"`
// Volumes is a collection of additional volumes to create for instances within this InstanceGroup
Volumes []*VolumeSpec `json:"volumes,omitempty"`
Volumes []VolumeSpec `json:"volumes,omitempty"`
// VolumeMounts a collection of volume mounts
VolumeMounts []*VolumeMountSpec `json:"volumeMounts,omitempty"`
VolumeMounts []VolumeMountSpec `json:"volumeMounts,omitempty"`
// Subnets is the names of the Subnets (as specified in the Cluster) where machines in this instance group should be placed
Subnets []string `json:"subnets,omitempty"`
// Zones is the names of the Zones where machines in this instance group should be placed
Expand Down
40 changes: 16 additions & 24 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go

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

40 changes: 10 additions & 30 deletions pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go

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

21 changes: 9 additions & 12 deletions pkg/apis/kops/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,24 @@ func ValidateClusterUpdate(obj *kops.Cluster, status *kops.ClusterStatus, old *k

// Validate etcd cluster changes
{
newClusters := make(map[string]*kops.EtcdClusterSpec)
newClusters := make(map[string]kops.EtcdClusterSpec)
for _, etcdCluster := range obj.Spec.EtcdClusters {
newClusters[etcdCluster.Name] = etcdCluster
}
oldClusters := make(map[string]*kops.EtcdClusterSpec)
oldClusters := make(map[string]kops.EtcdClusterSpec)
for _, etcdCluster := range old.Spec.EtcdClusters {
oldClusters[etcdCluster.Name] = etcdCluster
}

for k, newCluster := range newClusters {
fp := field.NewPath("spec", "etcdClusters").Key(k)

oldCluster := oldClusters[k]
if oldCluster != nil {
if oldCluster, ok := oldClusters[k]; ok {
allErrs = append(allErrs, validateEtcdClusterUpdate(fp, newCluster, status, oldCluster)...)
}
}
for k := range oldClusters {
newCluster := newClusters[k]
if newCluster == nil {
if _, ok := newClusters[k]; !ok {
fp := field.NewPath("spec", "etcdClusters").Key(k)
allErrs = append(allErrs, field.Forbidden(fp, "EtcdClusters cannot be removed"))
}
Expand All @@ -56,7 +54,7 @@ func ValidateClusterUpdate(obj *kops.Cluster, status *kops.ClusterStatus, old *k
return allErrs
}

func validateEtcdClusterUpdate(fp *field.Path, obj *kops.EtcdClusterSpec, status *kops.ClusterStatus, old *kops.EtcdClusterSpec) field.ErrorList {
func validateEtcdClusterUpdate(fp *field.Path, obj kops.EtcdClusterSpec, status *kops.ClusterStatus, old kops.EtcdClusterSpec) field.ErrorList {
allErrs := field.ErrorList{}

if obj.Name != old.Name {
Expand All @@ -75,20 +73,19 @@ func validateEtcdClusterUpdate(fp *field.Path, obj *kops.EtcdClusterSpec, status

// If the etcd cluster has been created (i.e. if we have status) then we can't support some changes
if etcdClusterStatus != nil {
newMembers := make(map[string]*kops.EtcdMemberSpec)
newMembers := make(map[string]kops.EtcdMemberSpec)
for _, member := range obj.Members {
newMembers[member.Name] = member
}
oldMembers := make(map[string]*kops.EtcdMemberSpec)
oldMembers := make(map[string]kops.EtcdMemberSpec)
for _, member := range old.Members {
oldMembers[member.Name] = member
}

for k, newMember := range newMembers {
fp := fp.Child("etcdMembers").Key(k)

oldMember := oldMembers[k]
if oldMember != nil {
if oldMember, ok := oldMembers[k]; ok {
allErrs = append(allErrs, validateEtcdMemberUpdate(fp, newMember, etcdClusterStatus, oldMember)...)
}
}
Expand All @@ -97,7 +94,7 @@ func validateEtcdClusterUpdate(fp *field.Path, obj *kops.EtcdClusterSpec, status
return allErrs
}

func validateEtcdMemberUpdate(fp *field.Path, obj *kops.EtcdMemberSpec, status *kops.EtcdClusterStatus, old *kops.EtcdMemberSpec) field.ErrorList {
func validateEtcdMemberUpdate(fp *field.Path, obj kops.EtcdMemberSpec, status *kops.EtcdClusterStatus, old kops.EtcdMemberSpec) field.ErrorList {
allErrs := field.ErrorList{}

if obj.Name != old.Name {
Expand Down
Loading

0 comments on commit 7d9f0a0

Please sign in to comment.