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

Infrastructure name #267

Merged
merged 3 commits into from
Jul 4, 2019
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 19 additions & 38 deletions Gopkg.lock

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

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ required = [
name = "github.com/aws/aws-sdk-go"
version = "1.19.47"

[[constraint]]
branch = "master"
name = "github.com/openshift/installer"

[[constraint]]
branch = "master"
name = "github.com/gophercloud/gophercloud"
Expand Down
1 change: 0 additions & 1 deletion manifests/02-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ rules:
- apiGroups:
- config.openshift.io
resources:
- clusterversions
- infrastructures
verbs:
- get
Expand Down
37 changes: 8 additions & 29 deletions pkg/clusterconfig/clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ package clusterconfig

import (
"fmt"
"strings"

"github.com/gophercloud/utils/openstack/clientconfig"
yamlv2 "gopkg.in/yaml.v2"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"
coreset "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"

configapiv1 "github.com/openshift/api/config/v1"

imageregistryv1 "github.com/openshift/cluster-image-registry-operator/pkg/apis/imageregistry/v1"
regopclient "github.com/openshift/cluster-image-registry-operator/pkg/client"
installer "github.com/openshift/installer/pkg/types"
"github.com/openshift/cluster-image-registry-operator/pkg/storage/util"
)

const (
installerConfigNamespace = "kube-system"
installerConfigName = "cluster-config-v1"
azureCredentialsName = "azure-credentials"
cloudCredentialsName = "installer-cloud-credentials"
azureCredentialsName = "azure-credentials"
cloudCredentialsName = "installer-cloud-credentials"
)

type StorageType string
Expand Down Expand Up @@ -85,35 +83,16 @@ func GetCoreClient(kubeconfig *rest.Config) (*coreset.CoreV1Client, error) {
return client, nil
}

func GetInstallConfig(kubeconfig *rest.Config) (*installer.InstallConfig, error) {
client, err := GetCoreClient(kubeconfig)
if err != nil {
return nil, err
}

cm, err := client.ConfigMaps(installerConfigNamespace).Get(installerConfigName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("unable to read cluster install configuration: %v", err)
}

installConfig := &installer.InstallConfig{}
if err := yaml.NewYAMLOrJSONDecoder(strings.NewReader(cm.Data["install-config"]), 100).Decode(installConfig); err != nil {
return nil, fmt.Errorf("unable to decode cluster install configuration: %v", err)
}

return installConfig, nil
}

func GetAWSConfig(kubeconfig *rest.Config, listers *regopclient.Listers) (*Config, error) {
cfg := &Config{}

installConfig, err := GetInstallConfig(kubeconfig)
infra, err := util.GetInfrastructure(kubeconfig)
if err != nil {
return nil, err
}

if installConfig.Platform.AWS != nil {
cfg.Storage.S3.Region = installConfig.Platform.AWS.Region
if infra.Status.PlatformStatus.Type == configapiv1.AWSPlatformType {
cfg.Storage.S3.Region = infra.Status.PlatformStatus.AWS.Region
}

client, err := GetCoreClient(kubeconfig)
Expand Down
8 changes: 0 additions & 8 deletions pkg/operator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (

const (
openshiftConfigNamespace = "openshift-config"
installerConfigNamespace = "kube-system"
workqueueKey = "changes"
defaultResyncDuration = 10 * time.Minute
)
Expand Down Expand Up @@ -371,7 +370,6 @@ func (c *Controller) Run(stopCh <-chan struct{}) error {
openshiftConfigKubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, defaultResyncDuration, kubeinformers.WithNamespace(openshiftConfigNamespace))
regopInformerFactory := regopinformers.NewSharedInformerFactory(regopClient, defaultResyncDuration)
routeInformerFactory := routeinformers.NewSharedInformerFactoryWithOptions(routeClient, defaultResyncDuration, routeinformers.WithNamespace(c.params.Deployment.Namespace))
installerConfigInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, defaultResyncDuration, kubeinformers.WithNamespace(installerConfigNamespace))

var informers []cache.SharedIndexInformer
for _, ctor := range []func() cache.SharedIndexInformer{
Expand Down Expand Up @@ -445,19 +443,13 @@ func (c *Controller) Run(stopCh <-chan struct{}) error {
c.listers.RegistryConfigs = informer.Lister()
return informer.Informer()
},
func() cache.SharedIndexInformer {
informer := installerConfigInformerFactory.Core().V1().Secrets()
c.listers.InstallerSecrets = informer.Lister().Secrets(installerConfigNamespace)
return informer.Informer()
},
} {
informer := ctor()
informer.AddEventHandler(c.handler())
informers = append(informers, informer)
}

configInformerFactory.Start(stopCh)
installerConfigInformerFactory.Start(stopCh)
kubeInformerFactory.Start(stopCh)
openshiftConfigKubeInformerFactory.Start(stopCh)
routeInformerFactory.Start(stopCh)
Expand Down
44 changes: 18 additions & 26 deletions pkg/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ func (d *driver) CreateStorage(cr *imageregistryv1.Config) error {
return err
}

ic, err := clusterconfig.GetInstallConfig(d.KubeConfig)
if err != nil {
return err
}

cv, err := util.GetClusterVersionConfig(d.KubeConfig)
infra, err := util.GetInfrastructure(d.KubeConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -290,7 +285,7 @@ func (d *driver) CreateStorage(cr *imageregistryv1.Config) error {
for i := 0; i < 5000; i++ {
// If the bucket name is blank, let's generate one
if len(d.Config.Bucket) == 0 {
d.Config.Bucket = fmt.Sprintf("%s-%s-%s-%s", imageregistryv1.ImageRegistryName, d.Config.Region, strings.Replace(string(cv.Spec.ClusterID), "-", "", -1), strings.Replace(string(uuid.NewUUID()), "-", "", -1))[0:62]
d.Config.Bucket = fmt.Sprintf("%s-%s-%s-%s", imageregistryv1.ImageRegistryName, d.Config.Region, strings.Replace(infra.Status.InfrastructureName, "-", "", -1), strings.Replace(string(uuid.NewUUID()), "-", "", -1))[0:62]
generatedName = true
}

Expand Down Expand Up @@ -367,28 +362,25 @@ func (d *driver) CreateStorage(cr *imageregistryv1.Config) error {
// Tag the bucket with the openshiftClusterID
// along with any user defined tags from the cluster configuration
if cr.Status.StorageManaged {
if ic.Platform.AWS != nil {
var tagSet []*s3.Tag
tagSet = append(tagSet, &s3.Tag{Key: aws.String("openshiftClusterID"), Value: aws.String(string(cv.Spec.ClusterID))})
for k, v := range ic.Platform.AWS.UserTags {
tagSet = append(tagSet, &s3.Tag{Key: aws.String(k), Value: aws.String(v)})
}

_, err := svc.PutBucketTagging(&s3.PutBucketTaggingInput{
Bucket: aws.String(d.Config.Bucket),
Tagging: &s3.Tagging{
TagSet: tagSet,
_, err := svc.PutBucketTagging(&s3.PutBucketTaggingInput{
Bucket: aws.String(d.Config.Bucket),
Tagging: &s3.Tagging{
TagSet: []*s3.Tag{
{
Key: aws.String("kubernetes.io/cluster/" + infra.Status.InfrastructureName),
Value: aws.String("owned"),
},
},
})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
util.UpdateCondition(cr, imageregistryv1.StorageTagged, operatorapi.ConditionFalse, aerr.Code(), aerr.Error())
} else {
util.UpdateCondition(cr, imageregistryv1.StorageTagged, operatorapi.ConditionFalse, "Unknown Error Occurred", err.Error())
}
},
})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
util.UpdateCondition(cr, imageregistryv1.StorageTagged, operatorapi.ConditionFalse, aerr.Code(), aerr.Error())
} else {
util.UpdateCondition(cr, imageregistryv1.StorageTagged, operatorapi.ConditionTrue, "Tagging Successful", "UserTags were successfully applied to the S3 bucket")
util.UpdateCondition(cr, imageregistryv1.StorageTagged, operatorapi.ConditionFalse, "Unknown Error Occurred", err.Error())
}
} else {
util.UpdateCondition(cr, imageregistryv1.StorageTagged, operatorapi.ConditionTrue, "Tagging Successful", "Tags were successfully applied to the S3 bucket")
}
}

Expand Down
Loading