Skip to content

Commit

Permalink
SKS-3010: Support custom host agent group (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
haijianyang committed Sep 12, 2024
1 parent d9ab098 commit e8a1aae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/pkg/errors"
agentv1 "github.com/smartxworks/host-config-agent-api/api/v1alpha1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
cgscheme "k8s.io/client-go/kubernetes/scheme"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
Expand All @@ -29,6 +30,7 @@ import (

infrav1 "github.com/smartxworks/cluster-api-provider-elf/api/v1beta1"
"github.com/smartxworks/cluster-api-provider-elf/pkg/context"
"github.com/smartxworks/cluster-api-provider-elf/pkg/vendor"
)

// Manager is a CAPE controller manager.
Expand All @@ -44,12 +46,13 @@ func New(ctx goctx.Context, opts Options) (Manager, error) {
// Ensure the default options are set.
opts.defaults()

_ = cgscheme.AddToScheme(opts.Scheme)
_ = clusterv1.AddToScheme(opts.Scheme)
_ = infrav1.AddToScheme(opts.Scheme)
_ = bootstrapv1.AddToScheme(opts.Scheme)
_ = controlplanev1.AddToScheme(opts.Scheme)
_ = agentv1.AddToScheme(opts.Scheme)
utilruntime.Must(cgscheme.AddToScheme(opts.Scheme))
utilruntime.Must(clusterv1.AddToScheme(opts.Scheme))
utilruntime.Must(infrav1.AddToScheme(opts.Scheme))
utilruntime.Must(bootstrapv1.AddToScheme(opts.Scheme))
utilruntime.Must(controlplanev1.AddToScheme(opts.Scheme))
vendor.InitHostAgentAPIGroup(&agentv1.GroupVersion, agentv1.SchemeBuilder)
utilruntime.Must(agentv1.AddToScheme(opts.Scheme))
// +kubebuilder:scaffold:scheme

// Build the controller manager.
Expand Down
32 changes: 32 additions & 0 deletions pkg/vendor/vendor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2024.
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 vendor

import (
"os"

"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

func InitHostAgentAPIGroup(groupVersion *schema.GroupVersion, schemeBuilder *scheme.Builder) {
hostAgentAPIGroup := os.Getenv("HOST_CONFIG_AGENT_API_GROUP")
if hostAgentAPIGroup != "" {
groupVersion.Group = hostAgentAPIGroup
schemeBuilder.GroupVersion = *groupVersion
}
}

0 comments on commit e8a1aae

Please sign in to comment.