Skip to content

Commit

Permalink
fix: add kube-nest-admission-plugins flag for virtual-cluster operator
Browse files Browse the repository at this point in the history
Signed-off-by: wangdepeng <[email protected]>
(cherry picked from commit 66125dc)
  • Loading branch information
village-way committed May 31, 2024
1 parent f964f9e commit 5969f10
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
6 changes: 4 additions & 2 deletions cmd/kubenest/operator/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type KubernetesOptions struct {
}

type KubeNestOptions struct {
ForceDestroy bool
AnpMode string
ForceDestroy bool
AnpMode string
AdmissionPlugins bool
}

func NewOptions() *Options {
Expand Down Expand Up @@ -55,4 +56,5 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.BoolVar(&o.KosmosJoinController, "kosmos-join-controller", false, "Turn on or off kosmos-join-controller.")
flags.BoolVar(&o.KubeNestOptions.ForceDestroy, "kube-nest-force-destroy", false, "Force destroy the node.If it set true.If set to true, Kubernetes will not evict the existing nodes on the node when joining nodes to the tenant's control plane, but will instead force destroy.")
flags.StringVar(&o.KubeNestOptions.AnpMode, "kube-nest-anp-mode", "tcp", "kube-apiserver network proxy mode, must be set to tcp or uds. uds mode the replicas for apiserver should be one, and tcp for multi apiserver replicas.")
flags.BoolVar(&o.KubeNestOptions.AdmissionPlugins, "kube-nest-admission-plugins", false, "kube-apiserver network disable-admission-plugins, false for - --disable-admission-plugins=License, true for remove the --disable-admission-plugins=License flag .")
}
9 changes: 6 additions & 3 deletions pkg/kubenest/controlplane/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
clientset "k8s.io/client-go/kubernetes"

"github.com/kosmos.io/kosmos/cmd/kubenest/operator/app/options"
"github.com/kosmos.io/kosmos/pkg/kubenest/constants"
"github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/apiserver"
"github.com/kosmos.io/kosmos/pkg/kubenest/util"
)

func EnsureVirtualClusterAPIServer(client clientset.Interface, name, namespace string, portMap map[string]int32) error {
if err := installAPIServer(client, name, namespace, portMap); err != nil {
func EnsureVirtualClusterAPIServer(client clientset.Interface, name, namespace string, portMap map[string]int32, opt *options.KubeNestOptions) error {
if err := installAPIServer(client, name, namespace, portMap, opt); err != nil {
return fmt.Errorf("failed to install virtual cluster apiserver, err: %w", err)
}
return nil
Expand All @@ -28,7 +29,7 @@ func DeleteVirtualClusterAPIServer(client clientset.Interface, name, namespace s
return nil
}

func installAPIServer(client clientset.Interface, name, namespace string, portMap map[string]int32) error {
func installAPIServer(client clientset.Interface, name, namespace string, portMap map[string]int32, opt *options.KubeNestOptions) error {
imageRepository, imageVersion := util.GetImageMessage()
clusterIp, err := util.GetEtcdServiceClusterIp(namespace, name+constants.EtcdSuffix, client)
if err != nil {
Expand All @@ -41,6 +42,7 @@ func installAPIServer(client clientset.Interface, name, namespace string, portMa
Replicas int32
EtcdListenClientPort int32
ClusterPort int32
AdmissionPlugins bool
}{
DeploymentName: fmt.Sprintf("%s-%s", name, "apiserver"),
Namespace: namespace,
Expand All @@ -53,6 +55,7 @@ func installAPIServer(client clientset.Interface, name, namespace string, portMa
Replicas: constants.ApiServerReplicas,
EtcdListenClientPort: constants.ApiServerEtcdListenClientPort,
ClusterPort: portMap[constants.ApiServerPortKey],
AdmissionPlugins: opt.AdmissionPlugins,
})
if err != nil {
return fmt.Errorf("error when parsing virtual cluster apiserver deployment template: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ spec:
- --max-mutating-requests-inflight=500
- --v=4
- --advertise-address=$(PODIP)
{{ if not .AdmissionPlugins }}
- --disable-admission-plugins=License
{{ end }}
livenessProbe:
failureThreshold: 8
httpGet:
Expand Down Expand Up @@ -222,6 +225,9 @@ spec:
- --v=4
- --advertise-address=$(PODIP)
- --egress-selector-config-file=/etc/kubernetes/konnectivity-server-config/{{ .Namespace }}/{{ .Name }}/egress_selector_configuration.yaml
{{ if not .AdmissionPlugins }}
- --disable-admission-plugins=License
{{ end }}
livenessProbe:
failureThreshold: 8
httpGet:
Expand Down
22 changes: 12 additions & 10 deletions pkg/kubenest/tasks/anp.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ func runAnpServer(r workflow.RunData) error {
portMap := data.HostPortMap()
// install egress_selector_configuration config map
egressSelectorConfig, err := util.ParseTemplate(apiserver.EgressSelectorConfiguration, struct {
Namespace string
Name string
AnpMode string
ProxyServerPort int32
SvcName string
Namespace string
Name string
AnpMode string
ProxyServerPort int32
SvcName string
AdmissionPlugins bool
}{
Namespace: namespace,
Name: name,
ProxyServerPort: portMap[constants.ApiServerNetworkProxyServerPortKey],
SvcName: fmt.Sprintf("%s-konnectivity-server.%s.svc.cluster.local", name, namespace),
AnpMode: kubeNestOpt.AnpMode,
Namespace: namespace,
Name: name,
ProxyServerPort: portMap[constants.ApiServerNetworkProxyServerPortKey],
SvcName: fmt.Sprintf("%s-konnectivity-server.%s.svc.cluster.local", name, namespace),
AnpMode: kubeNestOpt.AnpMode,
AdmissionPlugins: kubeNestOpt.AdmissionPlugins,
})
if err != nil {
return fmt.Errorf("failed to parse egress_selector_configuration config map template, err: %w", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/kubenest/tasks/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func runVirtualClusterAPIServer(r workflow.RunData) error {
data.GetName(),
data.GetNamespace(),
data.HostPortMap(),
data.KubeNestOpt(),
)
if err != nil {
return fmt.Errorf("failed to install virtual cluster apiserver component, err: %w", err)
Expand Down

0 comments on commit 5969f10

Please sign in to comment.