diff --git a/pkg/controller/all/all.go b/pkg/controller/all/all.go index 079e1b65..ffa56b57 100644 --- a/pkg/controller/all/all.go +++ b/pkg/controller/all/all.go @@ -19,7 +19,6 @@ package all import ( // register all controllers - _ "github.com/AliyunContainerService/terway/pkg/controller/endpoint" _ "github.com/AliyunContainerService/terway/pkg/controller/multi-ip/node" _ "github.com/AliyunContainerService/terway/pkg/controller/multi-ip/pod" _ "github.com/AliyunContainerService/terway/pkg/controller/node" diff --git a/pkg/controller/endpoint/endpoint.go b/pkg/controller/endpoint/endpoint.go deleted file mode 100644 index 5bc47408..00000000 --- a/pkg/controller/endpoint/endpoint.go +++ /dev/null @@ -1,114 +0,0 @@ -package endpoint - -import ( - "context" - "fmt" - "os" - "reflect" - "time" - - register "github.com/AliyunContainerService/terway/pkg/controller" - "github.com/AliyunContainerService/terway/pkg/utils/k8sclient" - - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/wait" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -var log = ctrl.Log.WithName("endpoint") - -const ControllerName = "endpoint" - -func init() { - register.Add(ControllerName, func(mgr manager.Manager, ctrlCtx *register.ControllerCtx) error { - ipStr := os.Getenv("MY_POD_IP") - if ipStr == "" { - return fmt.Errorf("podIP is not found") - } - // if enable Service name should equal cfg.ControllerName - ep := New(ctrlCtx.Config.ControllerName, ctrlCtx.Config.ControllerNamespace, ipStr, int32(ctrlCtx.Config.WebhookPort)) - return mgr.Add(ep) - }, false) -} - -// ReconcilePodNetworking implements reconcile.Reconciler -var _ manager.Runnable = &Endpoint{} - -// Endpoint reconciles a AutoRepair object -type Endpoint struct { - PodIP string - Name string - Namespace string - Port int32 -} - -func New(name, namespace, podIP string, port int32) *Endpoint { - return &Endpoint{ - PodIP: podIP, - Name: name, - Namespace: namespace, - Port: port, - } -} - -func (m *Endpoint) Start(ctx context.Context) error { - wait.Until(func() { - err := m.RegisterEndpoints() - if err != nil { - log.Error(err, "error sync endpoint") - } - }, time.Minute, ctx.Done()) - return fmt.Errorf("endpoint sync exited") -} - -// NeedLeaderElection need election -func (m *Endpoint) NeedLeaderElection() bool { - return true -} - -// RegisterEndpoints to endpoint -func (m *Endpoint) RegisterEndpoints() error { - newEPSubnet := []v1.EndpointSubset{ - { - Addresses: []v1.EndpointAddress{ - { - IP: m.PodIP, - }, - }, - Ports: []v1.EndpointPort{ - { - Name: "https", - Port: m.Port, - Protocol: "TCP", - }, - }, - }} - ctx := context.Background() - oldEP, err := k8sclient.K8sClient.CoreV1().Endpoints(m.Namespace).Get(ctx, m.Name, metav1.GetOptions{}) - if err != nil { - if !errors.IsNotFound(err) { - return err - } - _, err = k8sclient.K8sClient.CoreV1().Endpoints(m.Namespace).Create(ctx, &v1.Endpoints{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: m.Namespace, - Name: m.Name, - }, - Subsets: newEPSubnet, - }, metav1.CreateOptions{}) - log.Info("register endpoint", "ip", m.PodIP) - return err - } - - if reflect.DeepEqual(&oldEP.Subsets, &newEPSubnet) { - return nil - } - copyEP := oldEP.DeepCopy() - copyEP.Subsets = newEPSubnet - _, err = k8sclient.K8sClient.CoreV1().Endpoints(m.Namespace).Update(ctx, copyEP, metav1.UpdateOptions{}) - log.Info("register endpoint", "ip", m.PodIP) - return err -} diff --git a/types/controlplane/config.go b/types/controlplane/config.go index a3787697..20ee34db 100644 --- a/types/controlplane/config.go +++ b/types/controlplane/config.go @@ -93,10 +93,6 @@ func ParseAndValidate(configFilePath, credentialFilePath string) (*Config, error } } - if c.RegisterEndpoint { - c.Controllers = append(c.Controllers, "endpoint") - } - err = validator.New().Struct(&c) if err != nil { return nil, err diff --git a/types/controlplane/config_default.go b/types/controlplane/config_default.go index c10c43de..ca5357f8 100644 --- a/types/controlplane/config_default.go +++ b/types/controlplane/config_default.go @@ -42,7 +42,6 @@ type Config struct { WebhookPort int `json:"webhookPort" validate:"gt=0,lte=65535" mod:"default=4443"` CertDir string `json:"certDir" validate:"required" mod:"default=/var/run/webhook-cert"` LeaderElection bool `json:"leaderElection"` - RegisterEndpoint bool `json:"registerEndpoint"` // deprecated EnableTrace bool `json:"enableTrace"` PodMaxConcurrent int `json:"podMaxConcurrent" validate:"gt=0,lte=10000" mod:"default=10"`