Prefix ACI container groups with namespace name, also fix for container ports in ACI provider
This commit is contained in:
@@ -11,5 +11,11 @@ spec:
|
|||||||
requests:
|
requests:
|
||||||
memory: 1G
|
memory: 1G
|
||||||
cpu: 1
|
cpu: 1
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
name: http
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 443
|
||||||
|
name: https
|
||||||
dnsPolicy: ClusterFirst
|
dnsPolicy: ClusterFirst
|
||||||
nodeName: virtual-kubelet
|
nodeName: virtual-kubelet
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ func (p *ACIProvider) CreatePod(pod *v1.Pod) error {
|
|||||||
podUID := string(pod.UID)
|
podUID := string(pod.UID)
|
||||||
podCreationTimestamp := pod.CreationTimestamp.String()
|
podCreationTimestamp := pod.CreationTimestamp.String()
|
||||||
containerGroup.Tags = map[string]string{
|
containerGroup.Tags = map[string]string{
|
||||||
|
"PodName": pod.Name,
|
||||||
"ClusterName": pod.ClusterName,
|
"ClusterName": pod.ClusterName,
|
||||||
"NodeName": pod.Spec.NodeName,
|
"NodeName": pod.Spec.NodeName,
|
||||||
"Namespace": pod.Namespace,
|
"Namespace": pod.Namespace,
|
||||||
@@ -134,7 +135,7 @@ func (p *ACIProvider) CreatePod(pod *v1.Pod) error {
|
|||||||
// TODO(BJK) containergrouprestartpolicy??
|
// TODO(BJK) containergrouprestartpolicy??
|
||||||
_, err = p.aciClient.CreateContainerGroup(
|
_, err = p.aciClient.CreateContainerGroup(
|
||||||
p.resourceGroup,
|
p.resourceGroup,
|
||||||
pod.Name,
|
fmt.Sprintf("%s-%s", pod.Namespace, pod.Name),
|
||||||
containerGroup,
|
containerGroup,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -148,13 +149,13 @@ func (p *ACIProvider) UpdatePod(pod *v1.Pod) error {
|
|||||||
|
|
||||||
// DeletePod deletes the specified pod out of ACI.
|
// DeletePod deletes the specified pod out of ACI.
|
||||||
func (p *ACIProvider) DeletePod(pod *v1.Pod) error {
|
func (p *ACIProvider) DeletePod(pod *v1.Pod) error {
|
||||||
return p.aciClient.DeleteContainerGroup(p.resourceGroup, pod.Name)
|
return p.aciClient.DeleteContainerGroup(p.resourceGroup, fmt.Sprintf("%s-%s", pod.Namespace, pod.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPod returns a pod by name that is running inside ACI
|
// GetPod returns a pod by name that is running inside ACI
|
||||||
// returns nil if a pod by that name is not found.
|
// returns nil if a pod by that name is not found.
|
||||||
func (p *ACIProvider) GetPod(name string) (*v1.Pod, error) {
|
func (p *ACIProvider) GetPod(namespace, name string) (*v1.Pod, error) {
|
||||||
cg, err := p.aciClient.GetContainerGroup(p.resourceGroup, name)
|
cg, err := p.aciClient.GetContainerGroup(p.resourceGroup, fmt.Sprintf("%s-%s", namespace, name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Trap error for 404 and return gracefully
|
// Trap error for 404 and return gracefully
|
||||||
if strings.Contains(err.Error(), "ResourceNotFound") {
|
if strings.Contains(err.Error(), "ResourceNotFound") {
|
||||||
@@ -172,8 +173,8 @@ func (p *ACIProvider) GetPod(name string) (*v1.Pod, error) {
|
|||||||
|
|
||||||
// GetPodStatus returns the status of a pod by name that is running inside ACI
|
// GetPodStatus returns the status of a pod by name that is running inside ACI
|
||||||
// returns nil if a pod by that name is not found.
|
// returns nil if a pod by that name is not found.
|
||||||
func (p *ACIProvider) GetPodStatus(name string) (*v1.PodStatus, error) {
|
func (p *ACIProvider) GetPodStatus(namespace, name string) (*v1.PodStatus, error) {
|
||||||
pod, err := p.GetPod(name)
|
pod, err := p.GetPod(namespace, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -323,7 +324,7 @@ func (p *ACIProvider) getContainers(pod *v1.Pod) ([]aci.Container, error) {
|
|||||||
|
|
||||||
for _, p := range container.Ports {
|
for _, p := range container.Ports {
|
||||||
c.Ports = append(c.Ports, aci.ContainerPort{
|
c.Ports = append(c.Ports, aci.ContainerPort{
|
||||||
Port: p.HostPort,
|
Port: p.ContainerPort,
|
||||||
Protocol: getProtocol(p.Protocol),
|
Protocol: getProtocol(p.Protocol),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -553,7 +554,7 @@ func containerGroupToPod(cg *aci.ContainerGroup) (*v1.Pod, error) {
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: cg.Name,
|
Name: cg.Tags["PodName"],
|
||||||
Namespace: cg.Tags["Namespace"],
|
Namespace: cg.Tags["Namespace"],
|
||||||
ClusterName: cg.Tags["ClusterName"],
|
ClusterName: cg.Tags["ClusterName"],
|
||||||
UID: types.UID(cg.Tags["UID"]),
|
UID: types.UID(cg.Tags["UID"]),
|
||||||
|
|||||||
@@ -135,13 +135,13 @@ func (p *HyperProvider) DeletePod(pod *v1.Pod) error {
|
|||||||
|
|
||||||
// GetPod returns a pod by name that is running inside hyper.sh
|
// GetPod returns a pod by name that is running inside hyper.sh
|
||||||
// returns nil if a pod by that name is not found.
|
// returns nil if a pod by that name is not found.
|
||||||
func (p *HyperProvider) GetPod(name string) (*v1.Pod, error) {
|
func (p *HyperProvider) GetPod(namespace, name string) (*v1.Pod, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPodStatus returns the status of a pod by name that is running inside hyper.sh
|
// GetPodStatus returns the status of a pod by name that is running inside hyper.sh
|
||||||
// returns nil if a pod by that name is not found.
|
// returns nil if a pod by that name is not found.
|
||||||
func (p *HyperProvider) GetPodStatus(name string) (*v1.PodStatus, error) {
|
func (p *HyperProvider) GetPodStatus(namespace, name string) (*v1.PodStatus, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ type Provider interface {
|
|||||||
DeletePod(pod *v1.Pod) error
|
DeletePod(pod *v1.Pod) error
|
||||||
|
|
||||||
// GetPod retrieves a pod by name from the provider (can be cached).
|
// GetPod retrieves a pod by name from the provider (can be cached).
|
||||||
GetPod(name string) (*v1.Pod, error)
|
GetPod(namespace, name string) (*v1.Pod, error)
|
||||||
|
|
||||||
// GetPodStatus retrievesthe status of a pod by name from the provider.
|
// GetPodStatus retrievesthe status of a pod by name from the provider.
|
||||||
GetPodStatus(name string) (*v1.PodStatus, error)
|
GetPodStatus(namespace, name string) (*v1.PodStatus, error)
|
||||||
|
|
||||||
// GetPods retrieves a list of all pods running on the provider (can be cached).
|
// GetPods retrieves a list of all pods running on the provider (can be cached).
|
||||||
GetPods() ([]*v1.Pod, error)
|
GetPods() ([]*v1.Pod, error)
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ func (s *Server) reconcile() {
|
|||||||
// Create any pods for k8s pods that don't exist in the provider
|
// Create any pods for k8s pods that don't exist in the provider
|
||||||
pods := s.resourceManager.GetPods()
|
pods := s.resourceManager.GetPods()
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
p, err := s.provider.GetPod(pod.Name)
|
p, err := s.provider.GetPod(pod.Namespace, pod.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error retrieving pod '%s' from provider: %s\n", pod.Name, err)
|
log.Printf("Error retrieving pod '%s' from provider: %s\n", pod.Name, err)
|
||||||
}
|
}
|
||||||
@@ -296,6 +296,10 @@ func (s *Server) deletePod(pod *corev1.Pod) error {
|
|||||||
if !errors.IsNotFound(delErr) {
|
if !errors.IsNotFound(delErr) {
|
||||||
var grace int64 = 0
|
var grace int64 = 0
|
||||||
if err := s.k8sClient.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{GracePeriodSeconds: &grace}); err != nil && errors.IsNotFound(err) {
|
if err := s.k8sClient.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{GracePeriodSeconds: &grace}); err != nil && errors.IsNotFound(err) {
|
||||||
|
if errors.IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Failed to delete kubernetes pod: %s", err)
|
return fmt.Errorf("Failed to delete kubernetes pod: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +318,7 @@ func (s *Server) updatePodStatuses() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := s.provider.GetPodStatus(pod.Name)
|
status, err := s.provider.GetPodStatus(pod.Namespace, pod.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error retrieving pod '%s' status from provider: %s\n", pod.Name, err)
|
log.Printf("Error retrieving pod '%s' status from provider: %s\n", pod.Name, err)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user