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

Commit

Permalink
s/KubefedConfig/KubeFedConfig/
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed May 22, 2019
1 parent 1e3e2f3 commit a708544
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: core.kubefed.k8s.io/v1beta1
kind: KubefedConfig
kind: KubeFedConfig
metadata:
name: kubefed
namespace: {{ .Release.Namespace }}
Expand Down
52 changes: 26 additions & 26 deletions cmd/controller-manager/app/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func Run(opts *options.Options, stopChan <-chan struct{}) error {
panic(err)
}

setOptionsByKubefedConfig(opts)
setOptionsByKubeFedConfig(opts)

if err := utilfeature.DefaultFeatureGate.SetFromMap(opts.FeatureGates); err != nil {
klog.Fatalf("Invalid Feature Gate: %v", err)
Expand Down Expand Up @@ -181,13 +181,13 @@ func startControllers(opts *options.Options, stopChan <-chan struct{}) {
}
}

func getKubefedConfig(opts *options.Options) *corev1b1.KubefedConfig {
fedConfig := &corev1b1.KubefedConfig{}
func getKubeFedConfig(opts *options.Options) *corev1b1.KubeFedConfig {
fedConfig := &corev1b1.KubeFedConfig{}
if kubefedConfig == "" {
// there is no --kubefed-config specified, get `kubefed` KubefedConfig from the cluster
// there is no --kubefed-config specified, get `kubefed` KubeFedConfig from the cluster
client := genericclient.NewForConfigOrDieWithUserAgent(opts.Config.KubeConfig, "kubefedconfig")

name := util.KubefedConfigName
name := util.KubeFedConfigName
namespace := opts.Config.KubefedNamespace
qualifiedName := util.QualifiedName{
Namespace: namespace,
Expand All @@ -196,14 +196,14 @@ func getKubefedConfig(opts *options.Options) *corev1b1.KubefedConfig {

err := client.Get(context.Background(), fedConfig, namespace, name)
if apierrors.IsNotFound(err) {
klog.Infof("Cannot retrieve KubefedConfig %q: %v. Default options are used.", qualifiedName.String(), err)
klog.Infof("Cannot retrieve KubeFedConfig %q: %v. Default options are used.", qualifiedName.String(), err)
return nil
}
if err != nil {
klog.Fatalf("Error retrieving KubefedConfig %q: %v.", qualifiedName.String(), err)
klog.Fatalf("Error retrieving KubeFedConfig %q: %v.", qualifiedName.String(), err)
}

klog.Infof("Setting Options with KubefedConfig %q", qualifiedName.String())
klog.Infof("Setting Options with KubeFedConfig %q", qualifiedName.String())
return fedConfig
}

Expand All @@ -217,12 +217,12 @@ func getKubefedConfig(opts *options.Options) *corev1b1.KubefedConfig {
decoder := yaml.NewYAMLToJSONDecoder(file)
err = decoder.Decode(fedConfig)
if err != nil {
klog.Fatalf("Cannot decode KubefedConfig from file %q: %v", kubefedConfig, err)
klog.Fatalf("Cannot decode KubeFedConfig from file %q: %v", kubefedConfig, err)
}

// set to current namespace to make sure `KubefedConfig` is updated in correct namespace
// set to current namespace to make sure `KubeFedConfig` is updated in correct namespace
fedConfig.Namespace = opts.Config.KubefedNamespace
klog.Infof("Setting Options with KubefedConfig from file %q: %v", kubefedConfig, fedConfig.Spec)
klog.Infof("Setting Options with KubeFedConfig from file %q: %v", kubefedConfig, fedConfig.Spec)
return fedConfig
}

Expand All @@ -238,7 +238,7 @@ func setInt64(target *int64, defaultValue int64) {
}
}

func setDefaultKubefedConfig(fedConfig *corev1b1.KubefedConfig) {
func setDefaultKubeFedConfig(fedConfig *corev1b1.KubeFedConfig) {
spec := &fedConfig.Spec

if len(spec.Scope) == 0 {
Expand Down Expand Up @@ -278,55 +278,55 @@ func setDefaultKubefedConfig(fedConfig *corev1b1.KubefedConfig) {
}
}

func updateKubefedConfig(config *rest.Config, fedConfig *corev1b1.KubefedConfig) {
func updateKubeFedConfig(config *rest.Config, fedConfig *corev1b1.KubeFedConfig) {
name := fedConfig.Name
namespace := fedConfig.Namespace
qualifiedName := util.QualifiedName{
Namespace: namespace,
Name: name,
}

configResource := &corev1b1.KubefedConfig{}
configResource := &corev1b1.KubeFedConfig{}
client := genericclient.NewForConfigOrDieWithUserAgent(config, "kubefedconfig")
err := client.Get(context.Background(), configResource, namespace, name)
if err != nil && !apierrors.IsNotFound(err) {
klog.Fatalf("Error retrieving KubefedConfig %q: %v", qualifiedName, err)
klog.Fatalf("Error retrieving KubeFedConfig %q: %v", qualifiedName, err)
}
if apierrors.IsNotFound(err) {
// if `--kubefed-config` is specifed but there is not KubefedConfig resource accordingly
// if `--kubefed-config` is specifed but there is not KubeFedConfig resource accordingly
err = client.Create(context.Background(), fedConfig)
if err != nil {
klog.Fatalf("Error creating KubefedConfig %q: %v", qualifiedName, err)
klog.Fatalf("Error creating KubeFedConfig %q: %v", qualifiedName, err)
}
} else {
configResource.Spec = fedConfig.Spec
err = client.Update(context.Background(), configResource)
if err != nil {
klog.Fatalf("Error updating KubefedConfig %q: %v", qualifiedName, err)
klog.Fatalf("Error updating KubeFedConfig %q: %v", qualifiedName, err)
}
}
}

func setOptionsByKubefedConfig(opts *options.Options) {
fedConfig := getKubefedConfig(opts)
func setOptionsByKubeFedConfig(opts *options.Options) {
fedConfig := getKubeFedConfig(opts)
if fedConfig == nil {
// KubefedConfig could not be sourced from --kubefed-config or from the API.
// KubeFedConfig could not be sourced from --kubefed-config or from the API.
qualifiedName := util.QualifiedName{
Namespace: opts.Config.KubefedNamespace,
Name: util.KubefedConfigName,
Name: util.KubeFedConfigName,
}

klog.Infof("Creating KubefedConfig %q with default values", qualifiedName)
klog.Infof("Creating KubeFedConfig %q with default values", qualifiedName)

fedConfig = &corev1b1.KubefedConfig{
fedConfig = &corev1b1.KubeFedConfig{
ObjectMeta: metav1.ObjectMeta{
Name: qualifiedName.Name,
Namespace: qualifiedName.Namespace,
},
}
}

setDefaultKubefedConfig(fedConfig)
setDefaultKubeFedConfig(fedConfig)

spec := fedConfig.Spec
opts.Scope = spec.Scope
Expand All @@ -346,7 +346,7 @@ func setOptionsByKubefedConfig(opts *options.Options) {

opts.Config.SkipAdoptingResources = spec.SyncController.AdoptResources == corev1b1.AdoptResourcesDisabled

updateKubefedConfig(opts.Config.KubeConfig, fedConfig)
updateKubeFedConfig(opts.Config.KubeConfig, fedConfig)

var featureGates = make(map[string]bool)
for _, v := range fedConfig.Spec.FeatureGates {
Expand Down
2 changes: 1 addition & 1 deletion config/kubefedconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: core.kubefed.k8s.io/v1beta1
kind: KubefedConfig
kind: KubeFedConfig
metadata:
name: kubefed
namespace: kube-federation-system
Expand Down
2 changes: 1 addition & 1 deletion example/config/kubefedconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: core.kubefed.k8s.io/v1beta1
kind: KubefedConfig
kind: KubeFedConfig
metadata:
name: kubefed
namespace: kube-federation-system
Expand Down
18 changes: 9 additions & 9 deletions pkg/apis/core/v1beta1/kubefedconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// KubefedConfigSpec defines the desired state of KubefedConfig
type KubefedConfigSpec struct {
// KubeFedConfigSpec defines the desired state of KubeFedConfig
type KubeFedConfigSpec struct {
// The scope of the kubefed control plane should be either `Namespaced` or `Cluster`.
// `Namespaced` indicates that the kubefed namespace will be the only target for federation.
Scope apiextv1b1.ResourceScope `json:"scope"`
Expand Down Expand Up @@ -104,25 +104,25 @@ const (
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// KubefedConfig
// KubeFedConfig
// +k8s:openapi-gen=true
// +kubebuilder:resource:path=kubefedconfigs
type KubefedConfig struct {
type KubeFedConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KubefedConfigSpec `json:"spec"`
Spec KubeFedConfigSpec `json:"spec"`
}

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

// KubefedConfigList contains a list of KubefedConfig
type KubefedConfigList struct {
// KubeFedConfigList contains a list of KubeFedConfig
type KubeFedConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []KubefedConfig `json:"items"`
Items []KubeFedConfig `json:"items"`
}

func init() {
SchemeBuilder.Register(&KubefedConfig{}, &KubefedConfigList{})
SchemeBuilder.Register(&KubeFedConfig{}, &KubeFedConfigList{})
}
2 changes: 1 addition & 1 deletion pkg/controller/util/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
DefaultClusterHealthCheckSuccessThreshold = 1
DefaultClusterHealthCheckTimeout = 3

KubefedConfigName = "kubefed"
KubeFedConfigName = "kubefed"
)

// BuildClusterConfig returns a restclient.Config that can be used to configure
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubefedctl/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (j *joinFederation) Run(cmdOut io.Writer, config util.FedConfig) error {
return err
}

j.Scope, err = options.GetScopeFromKubefedConfig(hostConfig, j.KubefedNamespace)
j.Scope, err = options.GetScopeFromKubeFedConfig(hostConfig, j.KubefedNamespace)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/kubefedctl/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ func (o *CommonJoinOptions) SetName(args []string) error {
return nil
}

func GetScopeFromKubefedConfig(hostConfig *rest.Config, namespace string) (apiextv1b1.ResourceScope, error) {
func GetScopeFromKubeFedConfig(hostConfig *rest.Config, namespace string) (apiextv1b1.ResourceScope, error) {
client, err := genericclient.New(hostConfig)
if err != nil {
err = errors.Wrap(err, "Failed to get federation clientset")
return "", err
}

fedConfig := &fedv1b1.KubefedConfig{}
err = client.Get(context.TODO(), fedConfig, namespace, util.KubefedConfigName)
fedConfig := &fedv1b1.KubeFedConfig{}
err = client.Get(context.TODO(), fedConfig, namespace, util.KubeFedConfigName)
if err != nil {
config := util.QualifiedName{
Namespace: namespace,
Name: util.KubefedConfigName,
Name: util.KubeFedConfigName,
}
err = errors.Wrapf(err, "Error retrieving KubefedConfig %q", config)
err = errors.Wrapf(err, "Error retrieving KubeFedConfig %q", config)
return "", err
}

Expand Down

0 comments on commit a708544

Please sign in to comment.