Skip to content

Commit

Permalink
Add amd64 architecture node selector to velero (#3411) (#3421)
Browse files Browse the repository at this point in the history
  • Loading branch information
sancyx authored Feb 8, 2021
1 parent f18bacc commit 0910021
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 31 deletions.
56 changes: 48 additions & 8 deletions internal/ark/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package ark

import (
"encoding/json"
"fmt"

"emperror.dev/errors"
v1 "k8s.io/api/core/v1"

"github.com/banzaicloud/pipeline/internal/ark/client"
Expand All @@ -40,14 +42,15 @@ type ChartConfig struct {

// ValueOverrides describes values to be overridden in a deployment
type ValueOverrides struct {
Configuration configuration `json:"configuration"`
Credentials credentials `json:"credentials"`
Image image `json:"image"`
RBAC rbac `json:"rbac"`
InitContainers []v1.Container `json:"initContainers"`
CleanUpCRDs bool `json:"cleanUpCRDs"`
ServiceAccount serviceAccount `json:"serviceAccount"`
SecurityContext securityContext `json:"securityContext"`
Configuration configuration `json:"configuration"`
Credentials credentials `json:"credentials"`
Image image `json:"image"`
RBAC rbac `json:"rbac"`
InitContainers []v1.Container `json:"initContainers"`
CleanUpCRDs bool `json:"cleanUpCRDs"`
ServiceAccount serviceAccount `json:"serviceAccount"`
SecurityContext securityContext `json:"securityContext"`
Affinity map[string]interface{} `json:"affinity"`
}

type securityContext struct {
Expand Down Expand Up @@ -275,6 +278,23 @@ func (req ConfigRequest) Get() (values ValueOverrides, err error) {
},
InitContainers: initContainers,
CleanUpCRDs: true,
Affinity: map[string]interface{}{
"nodeAffinity": map[string]interface{}{
"requiredDuringSchedulingIgnoredDuringExecution": map[string]interface{}{
"nodeSelectorTerms": []map[string]interface{}{
{
"matchExpressions": []map[string]interface{}{
{
"key": "kubernetes.io/arch",
"operator": "In",
"values": []string{"amd64"},
},
},
},
},
},
},
},
}

if vsl.Provider == amazon.PersistentVolumeProvider && req.ServiceAccountRoleARN != "" {
Expand All @@ -295,6 +315,26 @@ func (req ConfigRequest) Get() (values ValueOverrides, err error) {
return values, nil
}

func (req *ConfigRequest) getChartConfig() (config ChartConfig, err error) {
config = GetChartConfig()

arkConfig, err := req.Get()
if err != nil {
err = errors.Wrap(err, "error getting config")
return
}

arkJSON, err := json.Marshal(arkConfig)
if err != nil {
err = errors.Wrap(err, "json convert failed")
return
}

config.ValueOverrides = arkJSON

return
}

func (req ConfigRequest) getVolumeSnapshotLocation() (volumeSnapshotLocation, error) {
var config volumeSnapshotLocation
var vslconfig volumeSnapshotLocationConfig
Expand Down
46 changes: 46 additions & 0 deletions internal/ark/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright © 2021 Banzai Cloud
//
// 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 ark

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestConfigRequest(t *testing.T) {
configRequest := ConfigRequest{
Cluster: clusterConfig{
Name: "test",
Provider: "amazon",
Distribution: "eks",
Location: "us-east-1",
RBACEnabled: false,
},
ClusterSecret: nil,
Bucket: bucketConfig{
Provider: "amazon",
Name: "testBucket",
Prefix: "test",
Location: "us-east-1",
},
BucketSecret: nil,
UseClusterSecret: false,

RestoreMode: false,
}
_, err := configRequest.getChartConfig()
require.NoError(t, err)
}
26 changes: 3 additions & 23 deletions internal/ark/deployments_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package ark

import (
"context"
"encoding/json"

"emperror.dev/errors"
"github.com/jinzhu/gorm"
Expand Down Expand Up @@ -127,7 +126,7 @@ func (s *DeploymentsService) Deploy(helmService HelmService, bucket *ClusterBack
}
}

config, err := s.getChartConfig(ConfigRequest{
req := ConfigRequest{
Cluster: clusterConfig{
Name: s.cluster.GetName(),
Provider: s.cluster.GetCloud(),
Expand All @@ -153,7 +152,8 @@ func (s *DeploymentsService) Deploy(helmService HelmService, bucket *ClusterBack
UseClusterSecret: useClusterSecret,
ServiceAccountRoleARN: serviceAccountRoleARN,
RestoreMode: restoreMode,
})
}
config, err := req.getChartConfig()
if err != nil {
return errors.Wrap(err, "error service getting config")
}
Expand Down Expand Up @@ -205,23 +205,3 @@ func (s *DeploymentsService) Remove(helmService HelmService) error {

return s.repository.Delete(deployment)
}

func (s *DeploymentsService) getChartConfig(req ConfigRequest) (config ChartConfig, err error) {
config = GetChartConfig()

arkConfig, err := req.Get()
if err != nil {
err = errors.Wrap(err, "error getting config")
return
}

arkJSON, err := json.Marshal(arkConfig)
if err != nil {
err = errors.Wrap(err, "json convert failed")
return
}

config.ValueOverrides = arkJSON

return
}

0 comments on commit 0910021

Please sign in to comment.