Skip to content

Commit

Permalink
Merge pull request #110 from senthilrch/develop
Browse files Browse the repository at this point in the history
Merge commits for v0.8.2 release
  • Loading branch information
senthilrch authored Sep 1, 2021
2 parents b7e37f4 + 304712a commit 088024e
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 82 deletions.
27 changes: 10 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ifndef OPERATOR_IMAGE_REPO
endif

ifndef RELEASE_VERSION
RELEASE_VERSION=v0.8.1
RELEASE_VERSION=v0.8.2
endif

ifndef DOCKER_VERSION
Expand Down Expand Up @@ -82,10 +82,6 @@ ifndef PROGRESS
PROGRESS=auto
endif

ifndef OPERATOR_NAMESPACE
OPERATOR_NAMESPACE=kubefledged-operator
endif

ifndef KUBEFLEDGED_NAMESPACE
KUBEFLEDGED_NAMESPACE=kube-fledged
endif
Expand Down Expand Up @@ -206,22 +202,20 @@ deploy-using-yaml:
kubectl rollout status deployment kubefledged-controller -n kube-fledged --watch

deploy-using-operator:
# Create the namespaces for operator and kubefledged
-kubectl create namespace ${OPERATOR_NAMESPACE}
# Create the namespace
-kubectl create namespace ${KUBEFLEDGED_NAMESPACE}
# Deploy the operator to a separate namespace
sed -i "s|{{OPERATOR_NAMESPACE}}|${OPERATOR_NAMESPACE}|g" deploy/kubefledged-operator/deploy/service_account.yaml
sed -i "s|{{OPERATOR_NAMESPACE}}|${OPERATOR_NAMESPACE}|g" deploy/kubefledged-operator/deploy/clusterrole_binding.yaml
sed -i "s|{{OPERATOR_NAMESPACE}}|${OPERATOR_NAMESPACE}|g" deploy/kubefledged-operator/deploy/operator.yaml
# Deploy the operator
sed -i "s|{{KUBEFLEDGED_NAMESPACE}}|${KUBEFLEDGED_NAMESPACE}|g" deploy/kubefledged-operator/deploy/service_account.yaml
sed -i "s|{{KUBEFLEDGED_NAMESPACE}}|${KUBEFLEDGED_NAMESPACE}|g" deploy/kubefledged-operator/deploy/clusterrole_binding.yaml
sed -i "s|{{KUBEFLEDGED_NAMESPACE}}|${KUBEFLEDGED_NAMESPACE}|g" deploy/kubefledged-operator/deploy/operator.yaml
kubectl apply -f deploy/kubefledged-operator/deploy/crds/charts.helm.kubefledged.io_kubefledgeds_crd.yaml
kubectl apply -f deploy/kubefledged-operator/deploy/service_account.yaml
kubectl apply -f deploy/kubefledged-operator/deploy/clusterrole.yaml
kubectl apply -f deploy/kubefledged-operator/deploy/clusterrole_binding.yaml
kubectl apply -f deploy/kubefledged-operator/deploy/operator.yaml
# Deploy kube-fledged to a separate namespace
sed -i "s|{{OPERATOR_NAMESPACE}}|${OPERATOR_NAMESPACE}|g" deploy/kubefledged-operator/deploy/crds/charts.helm.kubefledged.io_v1alpha2_kubefledged_cr.yaml
# Deploy kube-fledged
sed -i "s|{{KUBEFLEDGED_NAMESPACE}}|${KUBEFLEDGED_NAMESPACE}|g" deploy/kubefledged-operator/deploy/crds/charts.helm.kubefledged.io_v1alpha2_kubefledged_cr.yaml
kubectl rollout status deployment kubefledged-operator -n kubefledged-operator --watch
kubectl rollout status deployment kubefledged-operator -n ${KUBEFLEDGED_NAMESPACE} --watch
kubectl apply -f deploy/kubefledged-operator/deploy/crds/charts.helm.kubefledged.io_v1alpha2_kubefledged_cr.yaml

update:
Expand All @@ -239,17 +233,16 @@ remove-kubefledged:
-kubectl delete -f deploy/kubefledged-validatingwebhook.yaml

remove-operator-and-kubefledged:
# Remove kubefledged and the namespace
# Remove kubefledged
-kubectl delete -f deploy/kubefledged-operator/deploy/crds/charts.helm.kubefledged.io_v1alpha2_kubefledged_cr.yaml
-kubectl delete validatingwebhookconfigurations -l app.kubernetes.io/name=kube-fledged
-kubectl delete namespace ${KUBEFLEDGED_NAMESPACE}
# Remove the kubefledged operator and the namespace
-kubectl delete -f deploy/kubefledged-operator/deploy/operator.yaml
-kubectl delete -f deploy/kubefledged-operator/deploy/clusterrole_binding.yaml
-kubectl delete -f deploy/kubefledged-operator/deploy/clusterrole.yaml
-kubectl delete -f deploy/kubefledged-operator/deploy/service_account.yaml
-kubectl delete -f deploy/kubefledged-operator/deploy/crds/charts.helm.kubefledged.io_kubefledgeds_crd.yaml
-kubectl delete namespace ${OPERATOR_NAMESPACE}
-kubectl delete namespace ${KUBEFLEDGED_NAMESPACE}
-git checkout deploy/kubefledged-operator/deploy/operator.yaml
-git checkout deploy/kubefledged-operator/deploy/clusterrole_binding.yaml
-git checkout deploy/kubefledged-operator/deploy/service_account.yaml
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ _kube-fledged_ provides CRUD APIs to manage the lifecycle of the image cache, an
- [Quick Install using YAML manifests](#quick-install-using-yaml-manifests)
- [Quick Install using Helm chart](#quick-install-using-helm-chart)
- [Quick Install using Helm operator](#quick-install-using-helm-operator)
- [Helm chart parameters](#helm-chart-parameters)
- [Build and Deploy](#build-and-deploy)
- [Build](#build)
- [Deploy](#deploy)
Expand Down Expand Up @@ -113,7 +114,7 @@ These instructions install _kube-fledged_ to a separate namespace called "kube-f
$ cd $HOME/src/github.com/senthilrch/kube-fledged
```

- Deploy the helm operator to a separate namespace called "kubefledged-operator" and _kube-fledged_ to a separate namespace called "kube-fledged". If you need to deploy to a different namespace, export the variables OPERATOR_NAMESPACE and KUBEFLEDGED_NAMESPACE
- Deploy the helm operator and _kube-fledged_ to namespace "kube-fledged". If you need to deploy to a different namespace, export the variable KUBEFLEDGED_NAMESPACE

```
$ make deploy-using-operator
Expand All @@ -126,6 +127,10 @@ These instructions install _kube-fledged_ to a separate namespace called "kube-f
$ kubectl get imagecaches -n kube-fledged (Output should be: 'No resources found')
```

## Helm chart parameters

Parameters of the helm chart are documented [here](docs/helm-parameters.md)

## Build and Deploy

These instructions will help you build _kube-fledged_ from source and deploy it to a separate namespace called "kube-fledged". If you need to deploy it to a different namespace, edit the namespace field of the manifests in "kube-fledged/deploy" accordingly.
Expand Down
14 changes: 7 additions & 7 deletions cmd/controller/app/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,30 +221,30 @@ func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error {
defer c.imageworkqueue.ShutDown()

// Start the informer factories to begin populating the informer caches
glog.Info("Starting fledged controller")
glog.Info("Starting kubefledged-controller")

// Wait for the caches to be synced before starting workers
glog.Info("Waiting for informer caches to sync")
if ok := cache.WaitForCacheSync(stopCh, c.nodesSynced, c.imageCachesSynced); !ok {
return fmt.Errorf("failed to wait for caches to sync")
}
glog.Info("Informer caches synched successfull")

glog.Info("Starting image cache worker")
// Launch workers to process ImageCache resources
for i := 0; i < threadiness; i++ {
go wait.Until(c.runWorker, time.Second, stopCh)
}
glog.Info("Image cache worker started")

if c.imageCacheRefreshFrequency.Nanoseconds() != int64(0) {
glog.Info("Starting cache refresh worker")
go wait.Until(c.runRefreshWorker, c.imageCacheRefreshFrequency, stopCh)
glog.Info("Image cache refresh worker started")
}

glog.Info("Started workers")
c.imageManager.Run(stopCh)
if err := c.imageManager.Run(stopCh); err != nil {
glog.Fatalf("Error running image manager: %s", err.Error())
}
glog.Info("Image manager started")

<-stopCh
glog.Info("Shutting down workers")
Expand Down Expand Up @@ -577,7 +577,7 @@ func (c *Controller) syncHandler(wqKey images.WorkQueueKey) error {
status.Message = v1alpha2.ImageCacheMessageImagesPulledSuccessfully
}
}
if v.Status == images.ImageWorkResultStatusFailed && !failures {
if (v.Status == images.ImageWorkResultStatusFailed || v.Status == images.ImageWorkResultStatusUnknown) && !failures {
failures = true
status.Status = v1alpha2.ImageCacheActionStatusFailed
if v.ImageWorkRequest.WorkType == images.ImageCachePurge {
Expand All @@ -586,7 +586,7 @@ func (c *Controller) syncHandler(wqKey images.WorkQueueKey) error {
status.Message = v1alpha2.ImageCacheMessageImagePullFailedForSomeImages
}
}
if v.Status == images.ImageWorkResultStatusFailed {
if v.Status == images.ImageWorkResultStatusFailed || v.Status == images.ImageWorkResultStatusUnknown {
status.Failures[v.ImageWorkRequest.Image] = append(
status.Failures[v.ImageWorkRequest.Image], v1alpha2.NodeReasonMessage{
Node: v.ImageWorkRequest.Node.Labels["kubernetes.io/hostname"],
Expand Down
6 changes: 3 additions & 3 deletions deploy/kubefledged-deployment-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
spec:
initContainers:
- name: wait
image: senthilrch/kubefledged-cri-client:v0.8.1
image: senthilrch/kubefledged-cri-client:v0.8.2
command: ["curl"]
args:
- "--insecure"
Expand All @@ -31,7 +31,7 @@ spec:
- "https://kubefledged-webhook-server.kube-fledged.svc:3443/readyz"
imagePullPolicy: Always
containers:
- image: senthilrch/kubefledged-controller:v0.8.1
- image: senthilrch/kubefledged-controller:v0.8.2
command: ["/opt/bin/kubefledged-controller"]
args:
- "--stderrthreshold=INFO"
Expand All @@ -46,7 +46,7 @@ spec:
fieldRef:
fieldPath: metadata.namespace
- name: KUBEFLEDGED_CRI_CLIENT_IMAGE
value: "senthilrch/kubefledged-cri-client:v0.8.1"
value: "senthilrch/kubefledged-cri-client:v0.8.2"
- name: BUSYBOX_IMAGE
value: "gcr.io/google-containers/busybox:1.27.2"
serviceAccountName: kubefledged-controller
4 changes: 2 additions & 2 deletions deploy/kubefledged-deployment-webhook-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
app: kubefledged
spec:
initContainers:
- image: senthilrch/kubefledged-webhook-server:v0.8.1
- image: senthilrch/kubefledged-webhook-server:v0.8.2
command: ["/opt/bin/kubefledged-webhook-server"]
args:
- "--stderrthreshold=INFO"
Expand All @@ -40,7 +40,7 @@ spec:
- name: certkey-volume
mountPath: "/var/run/secrets/webhook-server"
containers:
- image: senthilrch/kubefledged-webhook-server:v0.8.1
- image: senthilrch/kubefledged-webhook-server:v0.8.2
command: ["/opt/bin/kubefledged-webhook-server"]
args:
- "--stderrthreshold=INFO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: kubefledged-operator
namespace: {{OPERATOR_NAMESPACE}}
namespace: {{KUBEFLEDGED_NAMESPACE}}
roleRef:
kind: ClusterRole
name: kubefledged-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@ apiVersion: charts.helm.kubefledged.io/v1alpha2
kind: KubeFledged
metadata:
name: kube-fledged
namespace: kubefledged-operator
namespace: {{KUBEFLEDGED_NAMESPACE}}
spec:
# Defaults defined in <project_dir>/helm-charts/kubefledged/values.yaml
kubefledgedNameSpace: kube-fledged
controllerReplicaCount: 1
webhookServerReplicaCount: 1
image:
kubefledgedControllerRepository: docker.io/senthilrch/kubefledged-controller
kubefledgedCRIClientRepository: docker.io/senthilrch/kubefledged-cri-client
kubefledgedWebhookServerRepository: docker.io/senthilrch/kubefledged-webhook-server
pullPolicy: Always
args:
controllerLogLevel: INFO
controllerImagePullDeadlineDuration: 5m
controllerImageCacheRefreshFrequency: 15m
controllerImagePullPolicy: IfNotPresent
webhookServerLogLevel: INFO
webhookServerCertFile: /var/run/secrets/webhook-server/tls.crt
webhookServerKeyFile: /var/run/secrets/webhook-server/tls.key
webhookServerPort: 443
nameOverride: ""
fullnameOverride: ""
4 changes: 2 additions & 2 deletions deploy/kubefledged-operator/deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: kubefledged-operator
namespace: {{OPERATOR_NAMESPACE}}
namespace: {{KUBEFLEDGED_NAMESPACE}}
spec:
replicas: 1
selector:
Expand All @@ -17,7 +17,7 @@ spec:
containers:
- name: kubefledged-operator
# Replace this with the built image name
image: docker.io/senthilrch/kubefledged-operator:v0.8.1
image: docker.io/senthilrch/kubefledged-operator:v0.8.2
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubefledged-operator/deploy/service_account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: kubefledged-operator
namespace: {{OPERATOR_NAMESPACE}}
namespace: {{KUBEFLEDGED_NAMESPACE}}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: v0.8.1
version: v0.8.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: v0.8.1
appVersion: v0.8.2
21 changes: 21 additions & 0 deletions docs/helm-parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Helm chart parameters

| Parameter | Default value | Description |
| --------- | ------------- | ----------- |
| controllerReplicaCount | 1 | No. of replicas of kubefledged-controller |
| webhookServerReplicaCount | 1 | No. of replicas of kubefledged-webhook-server |
| image.kubefledgedControllerRepository | docker.io/senthilrch/kubefledged-controller | Repository name of kubefledged-controller image |
| image.kubefledgedCRIClientRepository | docker.io/senthilrch/kubefledged-cri-client | Repository name of kubefledged-cri-client image |
| image.kubefledgedWebhookServerRepository | docker.io/senthilrch/kubefledged-webhook-server | Repository name of kubefledged-webhook-server image |
| image.pullPolicy | Always | Image pull policy for kubefledged-controller and kubefledged-webhook-server pods |
| args.controllerLogLevel | INFO | Log level of kubefledged-controller |
| args.controllerImagePullDeadlineDuration | 5m | Maximum duration allowed for pulling an image. After this duration, image pull is considered to have failed |
| args.controllerImageCacheRefreshFrequency | 15m | The image cache is refreshed periodically to ensure the cache is up to date. Setting this flag to "0s" will disable refresh |
| args.controllerImagePullPolicy | IfNotPresent | Image pull policy for pulling images into and refreshing the cache. Possible values are 'IfNotPresent' and 'Always'. Default value is 'IfNotPresent'. Image with no or ":latest" tag are always pulled |
| args.webhookServerLogLevel | INFO | Log level of kubefledged-webhook-server |
| args.webhookServerCertFile | /var/run/secrets/webhook-server/tls.crt | Path of server certificate of kubefledged-webhook-server |
| args.webhookServerKeyFile | /var/run/secrets/webhook-server/tls.key | Path of server key of kubefledged-webhook-server |
| args.webhookServerPort | 443 | Listening port of kubefledged-webhook-server |
| nameOverride | "" | nameOverride replaces the name of the chart in Chart.yaml, when this is used to construct Kubernetes object names |
| fullnameOverride | "" | fullnameOverride completely replaces the generated name |
| | | |
85 changes: 48 additions & 37 deletions pkg/images/image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (
ImageWorkResultStatusJobCreated = "jobcreated"
//ImageWorkResultStatusAlreadyPulled means image is already present in the node
ImageWorkResultStatusAlreadyPulled = "alreadypulled"
//ImageWorkResultStatusUnknown means status of image pull/delete unknown
ImageWorkResultStatusUnknown = "unknown"
)

// ImageManager provides the functionalities for pulling and deleting images
Expand Down Expand Up @@ -208,52 +210,61 @@ func (m *ImageManager) updatePendingImageWorkResults(imageCacheName string) erro
glog.Errorf("Error listing Pods: %v", err)
return err
}
if len(pods) == 0 {
glog.Errorf("No pods matched job %s", job)
return fmt.Errorf("no pods matched job %s", job)
}
if len(pods) > 1 {
glog.Errorf("More than one pod matched job %s", job)
return fmt.Errorf("more than one pod matched job %s", job)
}
iwres.Status = ImageWorkResultStatusFailed
if iwres.ImageWorkRequest.WorkType == ImageCachePurge {
glog.Infof("Job %s expired (delete: %s --> %s)", job, iwres.ImageWorkRequest.Image, iwres.ImageWorkRequest.Node.Labels["kubernetes.io/hostname"])
} else {
glog.Infof("Job %s expired (pull: %s --> %s)", job, iwres.ImageWorkRequest.Image, iwres.ImageWorkRequest.Node.Labels["kubernetes.io/hostname"])
}
if pods[0].Status.Phase == corev1.PodPending {
if len(pods[0].Status.ContainerStatuses) == 1 {
if pods[0].Status.ContainerStatuses[0].State.Waiting != nil {
iwres.Reason = pods[0].Status.ContainerStatuses[0].State.Waiting.Reason
iwres.Message = pods[0].Status.ContainerStatuses[0].State.Waiting.Message
}
if pods[0].Status.ContainerStatuses[0].State.Terminated != nil {
iwres.Reason = pods[0].Status.ContainerStatuses[0].State.Terminated.Reason
iwres.Message = pods[0].Status.ContainerStatuses[0].State.Terminated.Message
}
if len(pods) == 0 {
glog.Warningf("No pods matched job %s", job)
if iwres.ImageWorkRequest.WorkType == ImageCachePurge {
glog.Warningf("Job %s status unknown (delete: %s --> %s)", job, iwres.ImageWorkRequest.Image, iwres.ImageWorkRequest.Node.Labels["kubernetes.io/hostname"])
} else {
iwres.Reason = "Pending"
iwres.Message = "Check if node is ready"
glog.Warningf("Job %s status unknown (pull: %s --> %s)", job, iwres.ImageWorkRequest.Image, iwres.ImageWorkRequest.Node.Labels["kubernetes.io/hostname"])
}
iwres.Status = ImageWorkResultStatusUnknown
iwres.Reason = fmt.Sprintf("No pods matched job %s", job)
iwres.Message = fmt.Sprintf("No pods matched job %s", job)
}
if iwres.ImageWorkRequest.WorkType != ImageCachePurge {
fieldSelector := fields.Set{
"involvedObject.kind": "Pod",
"involvedObject.name": pods[0].Name,
"involvedObject.namespace": m.fledgedNameSpace,
"reason": "Failed",
}.AsSelector().String()

eventlist, err := m.kubeclientset.CoreV1().Events(m.fledgedNameSpace).
List(context.TODO(), metav1.ListOptions{FieldSelector: fieldSelector})
if err != nil {
glog.Errorf("Error listing events for pod (%s): %v", pods[0].Name, err)
return err
if len(pods) == 1 {
iwres.Status = ImageWorkResultStatusFailed
if iwres.ImageWorkRequest.WorkType == ImageCachePurge {
glog.Infof("Job %s expired (delete: %s --> %s)", job, iwres.ImageWorkRequest.Image, iwres.ImageWorkRequest.Node.Labels["kubernetes.io/hostname"])
} else {
glog.Infof("Job %s expired (pull: %s --> %s)", job, iwres.ImageWorkRequest.Image, iwres.ImageWorkRequest.Node.Labels["kubernetes.io/hostname"])
}
if pods[0].Status.Phase == corev1.PodPending {
if len(pods[0].Status.ContainerStatuses) == 1 {
if pods[0].Status.ContainerStatuses[0].State.Waiting != nil {
iwres.Reason = pods[0].Status.ContainerStatuses[0].State.Waiting.Reason
iwres.Message = pods[0].Status.ContainerStatuses[0].State.Waiting.Message
}
if pods[0].Status.ContainerStatuses[0].State.Terminated != nil {
iwres.Reason = pods[0].Status.ContainerStatuses[0].State.Terminated.Reason
iwres.Message = pods[0].Status.ContainerStatuses[0].State.Terminated.Message
}
} else {
iwres.Reason = "Pending"
iwres.Message = "Check if node is ready"
}
}
if iwres.ImageWorkRequest.WorkType != ImageCachePurge {
fieldSelector := fields.Set{
"involvedObject.kind": "Pod",
"involvedObject.name": pods[0].Name,
"involvedObject.namespace": m.fledgedNameSpace,
"reason": "Failed",
}.AsSelector().String()

eventlist, err := m.kubeclientset.CoreV1().Events(m.fledgedNameSpace).
List(context.TODO(), metav1.ListOptions{FieldSelector: fieldSelector})
if err != nil {
glog.Errorf("Error listing events for pod (%s): %v", pods[0].Name, err)
return err
}

for _, v := range eventlist.Items {
iwres.Message = iwres.Message + ":" + v.Message
for _, v := range eventlist.Items {
iwres.Message = iwres.Message + ":" + v.Message
}
}
}
m.imageworkstatus[job] = iwres
Expand Down
Loading

0 comments on commit 088024e

Please sign in to comment.