Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #217 from rfranzke/fix/worker-machine-image
Browse files Browse the repository at this point in the history
Worker delegates store machine image information in provider status
  • Loading branch information
timuthy authored Jul 29, 2019
2 parents 53edbc0 + d4de69d commit f933706
Show file tree
Hide file tree
Showing 90 changed files with 2,843 additions and 128 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

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

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ required = [

[[override]]
name = "github.com/gardener/gardener"
revision = "6138c5155cd19331947b375c9ae51b703e167dad"
revision = "130a96a2b463d9e5e1047122330f81e5b36501e2"

[[override]]
name = "github.com/gardener/machine-controller-manager"
Expand Down
12 changes: 12 additions & 0 deletions controllers/provider-alicloud/pkg/apis/alicloud/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ func FindSecurityGroupByPurpose(securityGroups []alicloud.SecurityGroup, purpose
}
return nil, fmt.Errorf("cannot find security group with purpose %q", purpose)
}

// FindMachineImage takes a list of machine images and tries to find the first entry
// whose name, version, and zone matches with the given name, version, and zone. If no such entry is
// found then an error will be returned.
func FindMachineImage(machineImages []alicloud.MachineImage, name, version string) (*alicloud.MachineImage, error) {
for _, machineImage := range machineImages {
if machineImage.Name == name && machineImage.Version == version {
return &machineImage, nil
}
}
return nil, fmt.Errorf("no machine image with name %q, version %q found", name, version)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ var _ = Describe("Helper", func() {
Entry("entry not found", []alicloud.SecurityGroup{{ID: "bar", Purpose: purposeWrong}}, purpose, nil, true),
Entry("entry exists", []alicloud.SecurityGroup{{ID: "bar", Purpose: purpose}}, purpose, &alicloud.SecurityGroup{ID: "bar", Purpose: purpose}, false),
)

DescribeTable("#FindMachineImage",
func(machineImages []alicloud.MachineImage, name, version string, expectedMachineImage *alicloud.MachineImage, expectErr bool) {
machineImage, err := FindMachineImage(machineImages, name, version)
expectResults(machineImage, expectedMachineImage, err, expectErr)
},

Entry("list is nil", nil, "foo", "1.2.3", nil, true),
Entry("empty list", []alicloud.MachineImage{}, "foo", "1.2.3", nil, true),
Entry("entry not found (no name)", []alicloud.MachineImage{{Name: "bar", Version: "1.2.3", ID: "id123"}}, "foo", "1.2.3", nil, true),
Entry("entry not found (no version)", []alicloud.MachineImage{{Name: "bar", Version: "1.2.3", ID: "id123"}}, "foo", "1.2.4", nil, true),
Entry("entry exists", []alicloud.MachineImage{{Name: "bar", Version: "1.2.3", ID: "id123"}}, "bar", "1.2.3", &alicloud.MachineImage{Name: "bar", Version: "1.2.3", ID: "id123"}, false),
)
})

func expectResults(result, expected interface{}, err error, expectErr bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&InfrastructureConfig{},
&InfrastructureStatus{},
&ControlPlaneConfig{},
&WorkerStatus{},
)
return nil
}
43 changes: 43 additions & 0 deletions controllers/provider-alicloud/pkg/apis/alicloud/types_worker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// 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 alicloud

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// WorkerStatus contains information about created worker resources.
type WorkerStatus struct {
metav1.TypeMeta

// MachineImages is a list of machine images that have been used in this worker. Usually, the extension controller
// gets the mapping from name/version to the provider-specific machine image data in its componentconfig. However, if
// a version that is still in use gets removed from this componentconfig it cannot reconcile anymore existing `Worker`
// resources that are still using this version. Hence, it stores the used versions in the provider status to ensure
// reconciliation is possible.
MachineImages []MachineImage
}

// MachineImage is a mapping from logical names and versions to provider-specific machine image data.
type MachineImage struct {
// Name is the logical name of the machine image.
Name string
// Version is the logical version of the machine image.
Version string
// ID is the id of the image.
ID string
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&InfrastructureConfig{},
&InfrastructureStatus{},
&ControlPlaneConfig{},
&WorkerStatus{},
)
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// 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 v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// WorkerStatus contains information about created worker resources.
type WorkerStatus struct {
metav1.TypeMeta `json:",inline"`

// MachineImages is a list of machine images that have been used in this worker. Usually, the extension controller
// gets the mapping from name/version to the provider-specific machine image data in its componentconfig. However, if
// a version that is still in use gets removed from this componentconfig it cannot reconcile anymore existing `Worker`
// resources that are still using this version. Hence, it stores the used versions in the provider status to ensure
// reconciliation is possible.
// +optional
MachineImages []MachineImage `json:"machineImages,omitempty"`
}

// MachineImage is a mapping from logical names and versions to provider-specific machine image data.
type MachineImage struct {
// Name is the logical name of the machine image.
Name string `json:"name"`
// Version is the logical version of the machine image.
Version string `json:"version"`
// ID is the id of the image.
ID string `json:"id"`
}

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

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

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

Loading

0 comments on commit f933706

Please sign in to comment.